I'm trying to get Proxyquire to work with a simple method substitution but I can't figure out what I'm doing wrong.
I create lib.js
module.exports = {
thing: () => {
console.log("thing");
}
};
And test.js
const lib = require("./lib");
module.exports = () => {
lib.thing();
};
And the and attempted to stub the dependency and replace thing with another function ie
const proxyquire = require("proxyquire");
const libStub = {};
const test = proxyquire("./test", {"lib": libStub});
test();
libStub.thing = () => {
console.log("replaced");
};
test();
But test is logging out "thing" both times instead of "replaced" on the second call. Any help is appreciated.
in proxyquire, use the same path that you use in the require itself :
so should be :