I have the following code which I am trying to test. However proxyquire
cannot find the readDirectory.js
. Does anyone understand why?
It's returning the following error, Error: Cannot find module '../readDirectory.js'
and point to the line were testedModule = proxyquire('../readDirectory.js', {
readDirectory.js
:
var dir = require('node-dir');
var _getFiles = {};
_getFiles._get = function (directory, callback) {
dir.readFiles(directory,
function(err, content, next) {
if (err) throw err;
console.log('content:', content);
});
};
module.exports = _getFiles;
tests:
var mockDir = require('mock-fs');
describe("readDirectory", function () {
var testedModule, callbackSpy, readFileStub;
before(function () {
mockDir({
tmp: {
images: {
thumb_test: "thumbnail pic",
small_test: "small pic",
medium_test: "medium pic"
}
}
});
readFileStub = sinon.stub();
callbackSpy = sinon.spy();
testedModule = proxyquire('../readDirectory.js', {
"node-dir": {
"readFiles": readFileStub
}
});
});
after(function () {
mockDir.restore();
});
it("call readdir with fake directory", function () {
testedModule._get(mockDir, function () {console.log("Hello");});
});
});