Created
August 5, 2015 15:49
-
-
Save telekosmos/8bb040e3a01685ee8ecb to your computer and use it in GitHub Desktop.
Stubbing a function that does not belong to an object
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
var jwt = function(x) { | |
console.log('transform stuff'); | |
} | |
function thingToBeTestedFactory(jwt) { | |
return function(x) { | |
return jwt(x); | |
}; | |
} | |
mocha.setup('bdd'); | |
var expect = chai.expect; | |
describe('Thing', function() { | |
it('should return a jwt-ed x', function() { | |
var jwtStub = sinon.stub(); | |
var factory = thingToBeTestedFactory(jwtStub); | |
var thingToBeTested = factory(5); | |
expect(jwtStub.calledOnce).to.be.true; | |
}); | |
}); | |
mocha.run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment