我有一个看起来像这样的单元测试
describe('Interceptor: myInterceptor', inject(function($rootScope){
var rootScope, routeParams = { id: null };
beforeEach(module('MyApp', function ($provide) {
$provide.factory('$routeParams', function () { // mock $routeParams
return routeParams;
});
rootScope = $rootScope.$new();
$provide.value('$rootScope', rootScope); // mock $rootScope
}));
....
}));
但是,当我执行上面显示的“inject(function($rootScope){ ..”时,我收到以下错误(使用 Karma 和 PhantomJS):
PhantomJS 1.9.2 (Mac OS X) Interceptor: myInterceptor encountered a declaration exception FAILED
TypeError: 'null' is not an object (evaluating 'currentSpec.$modules')
at workFn (/dev/myapp/app/bower_components/angular-mocks/angular-mocks.js:2072)
at /dev/myapp/test/spec/interceptors/my-interceptor.js:67
....