背景
- 发现了同事写的测试有瑕疵,需要他改进测试方法
- 提供追加测试的具体方法
具体
- jest test promises 参考
test('the data is peanut butter', () => {
return expect(fetchData()).resolves.toBe('peanut butter');
});
test('the fetch fails with an error', () => {
return expect(fetchData()).rejects.toMatch('error');
});
小结
- 确实需要从各个纬度保证项目的健壮性
- 看一个同事,先看他代码