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中运行,但是由于某种原因,都没有定义'require'或module,所以它最终在上述位置结束. /p>有什么想法吗?解决方案将karma-sinon-chai从1.0.0降级到0.3.2为我们解决了这个问题. github问题已经提起,我想这个问题很快就会解决. https://github.com/kmees/karma-sinon-chai/issues/21 npm install [email protected] --save-devI have unit tests running under Karma, and am using the sinon-chai library.Everything was working fine on Mac, but now I have moved to Windows the following error is occuring: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 useINFO [karma]: Karma v0.12.37 server started at http://localhost:9877/INFO [launcher]: Starting browser PhantomJSINFO [PhantomJS 1.9.8 (Windows 7 0.0.0)]: Connected on socket fMujwCqRPdmidI3BtCYV with id 16821903PhantomJS 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:17From that file: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}I would expect the condition on the first line to return true because I am running in Node, but for some reason neither 'require' or module are defined, so it ends up at the point indicated above.Any ideas? 解决方案 Downgrading karma-sinon-chai from 1.0.0 to 0.3.2 fixed this problem for us. A github issue has already been filed, I assume this will be fixed very quickly. https://github.com/kmees/karma-sinon-chai/issues/21npm install [email protected] --save-dev 这篇关于迁移到Windows后,karma-sinon-chai失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-09 08:26