Jest Tips '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');
});

小结

  • 确实需要从各个纬度保证项目的健壮性
  • 看一个同事,先看他代码

文章作者: せいい
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 せいい !
  目录