我对我的笑话测试运行了一份覆盖率报告,并收到了此输出。
SharedOfferThroughput
我去调查第27行,它显示为:
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
players.resolver.ts | 92.31 | 100 | 66.67 | 90.91 | 27 |
我的测试是:
27: @Query(returns => GetPlayer)
28: async GetPlayer(@Args('id') id: PlayerInput): Promise<Player> {
29: return await this.playerService.findOneById(id);
30: }
我在想类似的东西:
const res = {
id: 1,
firstName: 'First',
lastName: 'Last',
createdAt: new Date(),
updatedAt: new Date(),
};
const result: Promise<Player> = new Promise((resolve, reject) => {
return resolve(res);
});
jest
.spyOn(playersService, 'findOneById')
.mockImplementation(() => result);
const args = {
id: '1',
};
expect(await playersResolver.GetPlayer(args)).toBe(res);
});
,但在Jest文档中找不到。有一套用于测试依赖注入的工具吗?