Skip to content

Instantly share code, notes, and snippets.

@firatkucuk
Created January 4, 2015 20:48
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 firatkucuk/cf6a6acdd177b5871cfc to your computer and use it in GitHub Desktop.
Save firatkucuk/cf6a6acdd177b5871cfc to your computer and use it in GitHub Desktop.
sinon.js spy usage
'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