Skip to content

Instantly share code, notes, and snippets.

@yangchenyun
Created July 29, 2012 16:16
Show Gist options
  • Save yangchenyun/3200012 to your computer and use it in GitHub Desktop.
Save yangchenyun/3200012 to your computer and use it in GitHub Desktop.
stub test
describe "calculator", ->
it "should call the given method when parameter is valid", ->
# stub the method instead of just 'spying' it
minusStub = sinon.stub sample, 'minus'
methods = ['multiple', 'addition', 'minus', 'divide']
sample.calculator('minus', 1)
sinon.assert.calledOnce(minusStub)
sinon.assert.calledWithExactly(minusStub, [1])
# restore the minus method
minusStub.restore()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment