[英]How to test .subscribe method using jasmine karma unit testing where angular components is interacting with service?
I want to write a unit test case for .subscribe method for component.ts which is subscribin to a function in service.ts我想为component.ts的.subscribe方法编写一个单元测试用例,该方法订阅了service.ts中的函数
This is component.ts这是component.ts
this.certificationFormservice.getWishlist({ id: this.empid
}).subscribe(data => {
this.wishlist = data as any;
this.wishlist.forEach(element => {
this.certIdList.push(parseInt(element.certification_id));
});
This is service.ts这是service.ts
getWishlist(data) {
return this.http.post(environment.apiUrl + '/api/wishlist/get', data).pipe(
tap(
response => this.ui.spin$.next(false),
(error: any) => this.ui.spin$.next(false)
)
);
I want to write a unit test case for .subscribe method for component.ts which is subscribin to a function in service.ts我想为component.ts的.subscribe方法编写一个单元测试用例,该方法订阅了service.ts中的函数
This is component.ts这是component.ts
this.certificationFormservice.getWishlist({ id: this.empid
}).subscribe(data => {
this.wishlist = data as any;
this.wishlist.forEach(element => {
this.certIdList.push(parseInt(element.certification_id));
});
This is service.ts这是service.ts
getWishlist(data) {
return this.http.post(environment.apiUrl + '/api/wishlist/get', data).pipe(
tap(
response => this.ui.spin$.next(false),
(error: any) => this.ui.spin$.next(false)
)
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.