Created
January 4, 2015 20:48
-
-
Save firatkucuk/cf6a6acdd177b5871cfc to your computer and use it in GitHub Desktop.
sinon.js spy usage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var sinon = require('sinon'); | |
var assert = require('assert'); | |
var testObject = { | |
'testMethod': function () { | |
return 'testtest'; | |
} | |
}; | |
describe('sinon spy usage, our testMethod', function () { | |
var spyTestObject; | |
it('returns "testtest" normally', function () { | |
assert.equal(testObject.testMethod(), 'testtest'); | |
}); | |
it('returns "3" after 3 times call', function () { | |
spyTestObject = sinon.spy(testObject, 'testMethod'); | |
testObject.testMethod(); | |
testObject.testMethod(); | |
testObject.testMethod(); | |
assert.equal(testObject.testMethod.callCount, 3); | |
}); | |
it('returns "undefined" after restoring original state', function () { | |
spyTestObject.restore(); | |
testObject.testMethod(); | |
assert.equal(testObject.testMethod.callCount, undefined); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment