【发布时间】:2016-01-19 23:01:43
【问题描述】:
这是来自 karma.conf.js 文件:
module.exports = function (config) {
config.set({
frameworks: ['mocha', 'chai'],
files: [
'bower_components/angular/angular.js',
'bower_components/angular-mocks/angular-mocks.js',
'public/ng-app/module.js',
'public/ng-app/**/*.js',
'test/ng/**/*.spec.js'
],
...
我正在尝试像这样将 beforeEach 函数与注入一起使用:
describe('my.test', function () {
beforeEach(module('app'));
var MyService;
beforeEach(inject(function (_MyService_) {
MyService = _MyService_;
}));
describe('#send', function () {
it('exists', function () {
expect(MyService.save).to.exist;
});
});
});
但是 beforeEach(inject(function (...)...); 部分代码会导致此错误 当我尝试运行测试时:
PhantomJS 1.9.8 (Windows 8 0.0.0) my.test "before each" hook: workFn for "exists" FAILED
Error: [$injector:modulerr] Failed to instantiate module ng due to:
TypeError: 'undefined' is not an object (evaluating 'Function.prototype.bind.apply')
我不知道问题出在哪里。有人有什么想法吗?谢谢。
【问题讨论】:
标签: angularjs karma-mocha angular-mock