【发布时间】:2019-04-01 02:13:44
【问题描述】:
我有一个返回承诺的提供者对象。我正在尝试为此提供程序对象创建开玩笑的单元测试。
这是一个示例测试:
it('Should return repos for a known account', (done) => {
expect.assertions(1);
expect(apiProvider.ReposForUser('joon').then((data) => data.length)).resolves.toBeGreaterThan(0).then(done());
});
我现在只是在提供程序类中使用一个空白数组来解决承诺(即我希望测试失败):
export class GithubAPIProvider implements IGithubDataProvider {
public ReposForUser(githubUser: string): Promise<GithubRepoData[]> {
return new Promise<GithubRepoData[]>((resolve, reject) => {
resolve([]);
});
}
}
当我运行我的 jest 脚本时,我在输出文本中看到一个失败的 promise 错误,但测试显示已通过:
我在测试中使用了 done 回调,为什么 jest 不等待回调?
【问题讨论】:
标签: typescript jestjs