Skip to content

Instantly share code, notes, and snippets.

@cymen
Forked from jfirebaugh/example_spec.js.coffee
Created October 11, 2012 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cymen/3875554 to your computer and use it in GitHub Desktop.
Save cymen/3875554 to your computer and use it in GitHub Desktop.
Auto-restoring sinon fakes with Konacha
# require spec_helper
Test =
fn: -> 'result'
it 'auto-resets sinon fakes', ->
@stub(Test, 'fn')
Test.fn()
Test.fn.should.have.been.called
it 'has been reset', ->
Test.fn().should.equal('result')
# Injected by sinon.js
Konacha.mochaOptions.globals = [
'XMLHttpRequest'
'setTimeout'
'setInterval'
'clearTimeout'
'clearInterval'
]
#= require support/sinon
#= require support/sinon-chai
window.chai.use(window.sinonChai)
beforeEach ->
@sandbox = sinon.sandbox.create
injectInto: this
properties: ["spy", "stub", "mock", "clock", "server", "requests"],
useFakeTimers: true,
useFakeServer: true
afterEach ->
@sandbox.restore()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment