proxyquire not find module

时间:2015-05-13 13:01:57

标签: node.js testing proxyquire

我有以下代码,我正在尝试测试。但是proxyquire无法找到readDirectory.js。有谁理解为什么?

它返回以下错误Error: Cannot find module '../readDirectory.js'并指向该行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;

测试:

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");});

    });
});

0 个答案:

没有答案