Skip to content

Instantly share code, notes, and snippets.

@telekosmos
Created August 5, 2015 15:49
Show Gist options
  • Save telekosmos/8bb040e3a01685ee8ecb to your computer and use it in GitHub Desktop.
Save telekosmos/8bb040e3a01685ee8ecb to your computer and use it in GitHub Desktop.
Stubbing a function that does not belong to an object
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