In that case you have a couple of options:
- refactor your thingToBeTested code to be a factory. ie, your module would be a factory that takes the jwt function instead of require'ing jwt from inside thingToBeTested:
// thingToBeTested.js
// note: does not require jwt.js
module.exports = function thingToBeTestedFactory(jwt) {
return function thingToBeTested(x) {
return jwt(x);
};
}
in your code:
// app-setup.js
var jwt = require('./jwt.js'),
thingToBeTested = require('./thingToBeTested.js')(jwt);
in your test:
// test-thingToBeTested.js
var jwtStub = sinon.stub();
var thingToBeTested = require('./thingToBeTested.js')(jwtStub);