获取“TypeError:undefined不是函数!”在运行Karma测试套件时

时间:2015-11-16 16:04:28

标签: node.js karma-runner

当我尝试运行项目的业力测试套件(使用npm testkarma start)时,我得到了这个输出:

> game-engine@0.1.0 test /home/kent/dev/html5/game-engine
> karma start karma.conf.js --browsers PhantomJS

16 11 2015 16:50:11.910:INFO [karma]: Karma v0.13.15 server started at http://localhost:9876/
16 11 2015 16:50:11.921:INFO [launcher]: Starting browser PhantomJS
16 11 2015 16:50:12.109:INFO [PhantomJS 1.9.8 (Linux 0.0.0)]: Connected on socket opYF2pU3Qw-7rkdeAAAA with id 45780972
PhantomJS 1.9.8 (Linux 0.0.0) ERROR
  TypeError: undefined is not a function!
  at /home/kent/dev/html5/game-engine/node_modules/karma-babel-preprocessor/node_modules/babel-core/browser-polyfill.js:16

Finished in 0.12 secs / 0 secs

SUMMARY:
✔ 0 tests completed
npm ERR! Test failed.  See above for more details.

如果我查看上述文件的第16行,它看起来与模块有关:

module.exports = function(it){ //// Line 16
  if(typeof it != 'function')throw TypeError(it + ' is not a function!');
  return it;
};

整个文件可以在这里找到:http://pastebin.com/quHaY4NN

我使用这些版本:

$ node --version
v4.2.2
$ npm --version
2.14.7
$ karma --version
Karma version: 0.13.15

几个小时以来,我一直在抨击我。它会是什么样的问题?我该如何调试呢?

1 个答案:

答案 0 :(得分:3)

对我来说,解决方案是从karma-sinon-chai切换到替代karma-chai-sinon模块。

两者之间的区别在于后者的chaisinonsinon-chai peerDependencies (允许用户选择这些版本的使用);前者将它们作为依赖项(特别是它需要sinon ~1.16.0,其中有一个将setImmediate泄漏到全局范围的错误,打破任何setImmediate polyfills)。

如果您正在使用这些框架,那么您的问题并不清楚;但是,如果你是,这也可能是你的解决方案。

相关问题