1
我有一個非常大的AngularJS應用程序,我使用摩卡和柴(和JSDom)測試瀏覽器。完美的作品。不過,我現在正在嘗試使用伊斯坦布爾添加代碼覆蓋範圍,並且遇到有關Angular錯誤的問題。伊斯坦布爾代碼覆蓋摩卡和AngularJS
我的測試命令:mocha src/**/*.spec.js
覆蓋命令:istanbul cover _mocha src/**/*.spec.js
,我得到的錯誤是這樣的:
TypeError: Cannot read property '1' of null
at Function.annotate (node_modules/angular/angular.js:3810:24)
at Function.angular.injector.$$annotate (node_modules/angular-mocks/angular-mocks.js:2300:36)
at Object.invoke (node_modules/angular/angular.js:4514:36)
at Context.workFn (node_modules/angular-mocks/angular-mocks.js:2517:20)
Error: Declaration Location
at window.inject.angular.mock.inject (node_modules/angular-mocks/angular-mocks.js:2488:25)
at Suite.describe (src/components/filters/emoticonize.spec.js:9:407)
at Object.<anonymous> (src/components/filters/emoticonize.spec.js:9:183)
at Object.Module._extensions.(anonymous function) [as .js] (node_modules/istanbul/lib/hook.js:107:24)
at require (internal/module.js:20:19)
at Array.forEach (native)
at Object.Module._extensions.(anonymous function) [as .js] (node_modules/istanbul/lib/hook.js:109:37)
at runFn (node_modules/istanbul/lib/command/common/run-with-cover.js:122:16)
at node_modules/istanbul/lib/command/common/run-with-cover.js:251:17
at node_modules/istanbul/lib/util/file-matcher.js:68:16
at node_modules/async/lib/async.js:52:16
at node_modules/async/lib/async.js:361:13
at node_modules/async/lib/async.js:52:16
at done (node_modules/async/lib/async.js:246:17)
at node_modules/async/lib/async.js:44:16
at node_modules/async/lib/async.js:358:17
at FSReqWrap.oncomplete (fs.js:117:15)
這是錯誤發生:https://github.com/angular/angular.js/blob/v1.4.x/src/auto/injector.js#L101。我已經登錄fnText
存在和運行使用伊斯坦布爾測試時,該值是
_emoticonizeFilter_=>{__cov_OCFuCYwLZAl7nm5crSo1eg.s['7']++;emoticonizeFilter=_emoticonizeFilter_;}
我的測試:
require('../../../test-helper');
const expect = require('chai').expect;
describe('filter',() => {
let emoticonizeFilter;
beforeEach(angular.mock.module('components.filters'));
beforeEach(inject((_emoticonizeFilter_) => {
emoticonizeFilter = _emoticonizeFilter_;
}));
describe('emoticonize',() => {
it('should replace a smiley :) with emoji ',() => {
expect(emoticonizeFilter('Hello :)', true)).to.equal('Hello ');
});
it('should not replace smileys when given a falsy parameter',() => {
expect(emoticonizeFilter('Hello :)', false)).to.equal('Hello :)');
});
});
});
所以它打破在beforeEach
,我注入_emoticonizeFilter_
。伊斯坦布爾正在添加Angular不知道如何處理其註釋功能的東西。
我該如何解決這個問題?