I am trying to use proxyquire to stub a require in a module that is required by a 3rd party module.
Example:
My module requires a 3rd mod called 'foo'.
That module depends on another library called 'bar' and in bar there is a require I want to mock. Is this possible?
in 3rd party lib called 'three':
var bar = require('bar');
in bar lib:
var thingiwanttomock = require('thingiwanttomock');
Then something like this in my test:
it("test", function() {
var mocked = proxyquire('thingiwanttomock', {});
});
EDIT:
I think what I want is something like this:
var three = proxyquire('three', {
'bar': {
'thingiwanttomock': {
'mocked': true
}
}
}
});
However if I put a console log in the bar library and print out what the thingiwanttomock variable is after the require, its not my mocked object.
in bar lib:
var thingiwanttomock = require('thingiwanttomock');
// this is not my object object
console.log('thingiwanttomock should be a mock', thingiwanttomock);
Will proxyquire actually change what gets pulled in from a require statement in the dependent lib? Maybe that is where my confusion lies.