如何在 angular 7 中使用 jasmine 和 karma 编写单元测试用例
How to write unit test case using jasmine and karma in angular 7
我必须在 ts 文件中的函数中为以下代码编写单元测试用例
logout() {
this.cookieService.delete('deleted_cookie_name');
}
I have writtern like this using spy.
cookieService=jasmine.createSpyObj(['delete'])
我会做如下的事情;
it('should delete cookie name', inject([CookieService], (cookieService: CookieService) => {
const serviceSpy = spyOn(cookieService, 'delete');
component.logout();
expect(serviceSpy).toHaveBeenCalled();
}
))
我必须在 ts 文件中的函数中为以下代码编写单元测试用例
logout() {
this.cookieService.delete('deleted_cookie_name');
}
I have writtern like this using spy.
cookieService=jasmine.createSpyObj(['delete'])
我会做如下的事情;
it('should delete cookie name', inject([CookieService], (cookieService: CookieService) => {
const serviceSpy = spyOn(cookieService, 'delete');
component.logout();
expect(serviceSpy).toHaveBeenCalled();
}
))