我正在尝试测试简单的代码:
function div2(a, b) {
return a/b;
}
module.exports.div = div2;
在 examplesTestUnit.js 文件中:
var calculator = require("./examples");
module.exports["div test"] = function(test) {
test.equal(calculator.div(6,2), 3);
test.equal(calculator.div(12,0), Infinity);
test.equal(calculator.div(0,3), 0);
test.done();
};
当我尝试在 Webstorm 中运行测试时出现错误:
/usr/bin/node /tmp/nodeunit-intellij-starter.js /usr/lib/node_modules/nodeunit examplesTestUnit.js
Testing started at 02:42 ...
module.js:340
throw err;
^
Error: Cannot find module '/usr/lib/node_modules/nodeunit/deps/async'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at resolveAsyncModule (/tmp/nodeunit-intellij-starter.js:304:20)
at testIt (/tmp/nodeunit-intellij-starter.js:308:21)
at run (/tmp/nodeunit-intellij-starter.js:335:9)
at Object.<anonymous> (/tmp/nodeunit-intellij-starter.js:365:1)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
Process finished with exit code 8
我安装了 mocha 进行测试,mocha 没有给我一个错误,但仍然没有结果:
[DzikiChrzan@DzikiLaptopF untitled]$ mocha examplesTestUnit.js
0 passing (1ms)
[DzikiChrzan@DzikiLaptopF untitled]$
我已经安装了 0.8.6 版本的 nodeunit,我已经尝试重新安装它。加上我在终端收到的另一个错误:
[DzikiChrzan@DzikiLaptopF untitled]$ nodeunit --
/usr/lib/node_modules/nodeunit/lib/nodeunit.js:72
if (err) throw err;
^
Error: ENOENT, stat '/home/DzikiChrzan/WebstormProjects/untitled/--'
我正在使用 Fedora 22。我该如何解决这个问题?