angular 测试哪个 returns 函数
angular test which returns function
我在下面写了测试用例,但它没有涵盖这一行:() => service.getUserProfile()
export function userServiceFactory(service: UserService) {
return () => service.getUserProfile();
}
测试:
import * as userserv from './user.service';
it('should call userServiceFactory function', () => {
const spy = spyOn(userService, 'getUserProfile').and.callThrough();
userService.getUserProfile();
const result = userserv.userServiceFactory(userService);
expect(spy).toHaveBeenCalled();
expect(result).toBeDefined();
});
it('should call userServiceFactory and invoke getUserProfile ', () => {
const getUserProfileSpy = spyOn(userService, 'getUserProfile') ;
const result = userserv.userServiceFactory(userService);
result.call(userService.getUserProfile);
expect(getUserProfileSpy).toHaveBeenCalled();
});
我在下面写了测试用例,但它没有涵盖这一行:() => service.getUserProfile()
export function userServiceFactory(service: UserService) {
return () => service.getUserProfile();
}
测试:
import * as userserv from './user.service';
it('should call userServiceFactory function', () => {
const spy = spyOn(userService, 'getUserProfile').and.callThrough();
userService.getUserProfile();
const result = userserv.userServiceFactory(userService);
expect(spy).toHaveBeenCalled();
expect(result).toBeDefined();
});
it('should call userServiceFactory and invoke getUserProfile ', () => {
const getUserProfileSpy = spyOn(userService, 'getUserProfile') ;
const result = userserv.userServiceFactory(userService);
result.call(userService.getUserProfile);
expect(getUserProfileSpy).toHaveBeenCalled();
});