我的代码如下:
const myFunc =() =>{ setTimeout(()=>throw new Error('err within setTimeout'),500); }
如何在Jest框架中测试是否引发了错误?
您可以这样测试:
it('should throw an error', () => { expect(myFunc).toThrowError('err within setTimeout') })
检查此article