我有在 Karma 下运行的单元测试,并且正在使用 sinon-chai 库。
在 Mac 上一切正常,但现在我已移至 Windows,出现以下错误:
C:\Users\mchambe4\dev\simple\client>node ./node_modules/gulp/bin/gulp.js unit-tests-dev
[16:29:31] Using gulpfile ~\dev\simple\client\gulpfile.js
[16:29:31] Starting 'unit-tests-dev'...
[16:29:31] Starting Karma server...
WARN [karma]: Port 9876 in use
INFO [karma]: Karma v0.12.37 server started at http://localhost:9877/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.8 (Windows 7 0.0.0)]: Connected on socket fMujwCqRPdmidI3BtCYV with id 16821903
PhantomJS 1.9.8 (Windows 7 0.0.0) ERROR
ReferenceError: Can't find variable: chai
at C:/Users/mchambe4/dev/simple/client/node_modules/karma-sinon-chai/node_modules/sinon-chai/lib/sinon-chai.js:17
从那个文件:
if (typeof require === "function" && typeof exports === "object" && typeof module === "object") {
// NodeJS
module.exports = sinonChai; // <---- should go in here
} else if (typeof define === "function" && define.amd) {
// AMD
define(function () {
return sinonChai;
});
} else {
// Other environment (usually <script> tag): plug in to global chai instance directly.
chai.use(sinonChai); // <---- actually ends up here
}
我希望第一行的条件会返回true
,因为我在 Node 中运行,但由于某种原因既不是“要求”也不module
是定义的,所以它最终在上面指出的点结束。
有任何想法吗?