Last active
August 29, 2015 14:12
-
-
Save firatkucuk/b958034f8c9420e9f377 to your computer and use it in GitHub Desktop.
sinon.js stub usage
This file contains 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 stub usage, our testMethod', function () { | |
var stubTestObject; | |
it('returns "testtest" normally', function () { | |
assert.equal(testObject.testMethod(), 'testtest'); | |
}); | |
it('returns "hello" after stub usage', function () { | |
stubTestObject = sinon.stub(testObject, 'testMethod', function() { | |
return 'hello'; | |
}); | |
assert.equal(testObject.testMethod(), 'hello'); | |
}); | |
it('returns "testtest" after restoring original state', function () { | |
stubTestObject.restore(); | |
assert.equal(testObject.testMethod(), 'testtest'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment