在Buster.jstesting中导入其他.js文件
我正在做第一次尝试Javascripttesting,用Buster.js
我已经按照Buster网站上的说明运行了“明显的”testing。 但是,我还没有能够将任何现有的.js文件导入到testing中。
例如,我有一个文件js/testLibrary.js
,其中包含:
function addTwo(inp) { return inp+2; }
和一个文件test/first-test.js
,其中包含:
// Node.js tests var buster = require("buster"); var testLibrary = require("../js/testLibrary.js"); var assert = buster.referee.assert; buster.testCase("A module", { "Test The Library": function() { result = addTwo(3); console.log(result); assert(true, 'a message for you'); } });
运行buster-test
给出:
Error: A module Test The Library ReferenceError: addTwo is not defined [...]
replaceresult = addTwo(3);
result = testLibrary.addTwo(3);
得到:
Error: A module Test The Library TypeError: Object #<Object> has no method 'addTwo' [...]
我可能错过了一些非常基本的东西,但是目前我完全被困住了。 有人能指出我正确的方向吗?
那是因为你没有从模块中导出这个函数。 看看这个: http : //nodejs.org/api/modules.html#modules_module_exports