Vin*_*nay 7 typescript karma-runner istanbul karma-jasmine angular
我正在unit test
为我的component
(Angular2应用程序)编写一个使用Karma-Jasmine
.我正在使用Istanbul
代码覆盖率报告.
这是我的测试用例,
it('Should Invoke onNext function', async(() => {
const fixture = TestBed.createComponent(LoginComponent);
fixture.detectChanges();
const login = fixture.componentInstance;
spyOn(login, 'onNext');
let email = fixture.debugElement.nativeElement.querySelector("input[name='username']");
email.value = "email";
let nextButton = fixture.debugElement.nativeElement.querySelectorAll("button")[1];
nextButton.click();
fixture.whenStable().then(() => {
expect(login.onNext).toHaveBeenCalled();
})
}));
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我spying on onNext function
将验证它是否被调用nextbutton click
.它工作正常,测试通过.
但是我的"登录"页面的代码覆盖率报告显示未涵盖onNext函数.
我究竟做错了什么??
如果我不监视onNext函数,该函数也会被覆盖,
it('Should Invoke onNext function', async(() => {
const fixture = TestBed.createComponent(LoginComponent);
fixture.detectChanges();
const login = fixture.componentInstance;
let email = fixture.debugElement.nativeElement.querySelector("input[name='username']");
email.value = "email";
let nextButton = fixture.debugElement.nativeElement.querySelectorAll("button")[1];
nextButton.click();
}));
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1374 次 |
最近记录: |