I’m trying to go with a red/green/refactor pattern and want to spec a button that at first does not exist, then exists but is not hooked up to an event handler, then is hooked up to an event handler and finally creates UI side effects when clicked.
Is this kind of end-to-end stuff worth pursuing using mocha and sinon or should I be looking at Jasmine?
My initial cut at the code went something like this:
expect = chai.expect
MochaWeb?.testOnly ->
describe "Events Page", ->
it "Has an 'add event' button", ->
addEventButton = $('button#add-event')
expect(addEventButton).to.not.be.null
it "Triggers a handler on add event click", ->
# I would even stub Template if I knew how
home = stubs.create('home', Template, 'home')
events = stubs.create('events', Template.home, 'events')
spies.create 'addEvent', Template.home.events, 'addEvent'
stubs.get('events').call 'addEvent'
expect(spies.addEvent).to.have.been.called()
result: expected [Function] to be an object
It would be great if someone could point me in the right direction here. Thanks!