Closed tamtakoe closed 8 years ago
Proxyquire isn't doing anything fancy with your paths. It expects exact matches between your require
calls and your stub objects.
It is strange, because node.js always resolves paths and a developer expects the same behavior from node.js modules.
The second strange thing that I encountered is merging native module with mock module. F.e. If I have
module.js
module.exports = {a: 1, b: 1};
module.mock.js
module.exports = {a: 2};
index.js
var module = require('./module');
console.log(module);
index.test.js
proxyquire('./index', {
'./module': require('./module.mock')
});
I will get in console:
{a: 2, b: 1};
It is very strange behavior. Of course I will get error if module.js contains dependencies which can't be resolved with test framework. Every adequate developer expects that his mock will change particular dependency and original module will never be launched.
Unfortunately proxyquire can't be used for tests now :(
smth.js
smth.test.js
It works. But if I change proxyquire dependency path for
'./../utils/index': utils
or'../utils/../utils/index': utils
it doesn't work, because path hasn't been resolved