angularjs
基于组件,运行良好,但在任何情况下都要考虑测试覆盖率
window.addEventListener('message',
未涵盖。
我应该嘲笑
window
addEventListener
? 或者监视它并检查它是否被调用?
export class MyComponentController {
constructor() {}
public theEventOccurred(e: any) {
let json = JSON.parse(e.data);
console.log(json.document);
}
public $onInit() {
window.addEventListener('message', (event) => {
this.theEventOccurred(event);
}, false);
}
}
describe('Component: my', () => {
let $componentController: angular.IComponentControllerService;
let scope: angular.IScope;
beforeEach(inject(
($rootScope: angular.IScope,
_$componentController_: angular.IComponentControllerService) => {
scope = $rootScope.$new();
$componentController = _$componentController_;
}));
describe('Controller: MyComponentController', () => {
it('should log json.document', () => {
let ctrl: any = $componentController('my', { $scope: scope });
ctrl.$onInit();
});
});
});