我不断收到错误消息:
UserService单元测试getNumberOfUsers()规格没有期望 应该返回用户总数
当我定义如下期望值时:
describe('getNumberOfUsers()', () => {
it('should return total number of users',
inject([UserService], (userService) => {
let noOfUsers = 0;
userService.getNumberOfUsers().subscribe((result) => {
noOfUsers = result.data.counter;
expect(noOfUsers).toBeGreaterThan(0);
});
}));
我该如何解决?
答案 0 :(得分:1)
您需要提供茉莉花的DoneFn
describe('getNumberOfUsers()', () => {
it('should return total number of users', (done: DoneFn) => { // supply DoneFn
inject([UserService], (userService) => {
let noOfUsers = 0;
userService.getNumberOfUsers().subscribe((result) => {
noOfUsers = result.data.counter;
expect(noOfUsers).toBeGreaterThan(0);
done(); //call DoneFn
});
})(); // immediatly call inject function
});
})
查看更多信息