Skip to content

Instantly share code, notes, and snippets.

@parris
Created August 4, 2014 05:47
Show Gist options
  • Save parris/0431861d64a81ff7f220 to your computer and use it in GitHub Desktop.
Save parris/0431861d64a81ff7f220 to your computer and use it in GitHub Desktop.
Example Mocha ReactJS + CoffeeScript Test
Parse = require '../../core/parse'
TestUtils = require('react/addons').addons.TestUtils
logoutView = require './logout'
mediator = require '../../core/mediator'
describe 'LogoutView', ->
beforeEach ->
@container = @document.createElement 'div'
@logoutEl = TestUtils.renderIntoDocument <logoutView />, @container
describe 'once logout is clicked', ->
beforeEach ->
@parseLogoutStub = @sinon.stub Parse.User, 'logOut'
@logoutMediatorStub = @sinon.stub()
mediator.on 'user:loggedOut', @logoutMediatorStub
@routerSpy = @sinon.spy(mediator.get('router'), 'goto')
TestUtils.Simulate.click @logoutEl.getDOMNode()
afterEach ->
@parseLogoutStub.restore()
@routerSpy.restore()
it 'logs users out via parse', ->
@parseLogoutStub.called.should.be.ok
it 'triggers a global logout event', ->
@logoutMediatorStub.called.should.be.ok
it 'routes to /session', ->
@routerSpy.called.should.be.ok
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment