3 回答
TA贡献1788条经验 获得超4个赞
我认为你需要的是检查被拒绝的错误
const foo = require('./foo');
describe('foo', () => {
it('should log and rethrow', async () => {
await expect(foo()).rejects.toEqual('error');
});
});
TA贡献1829条经验 获得超9个赞
似乎这是一个已知的错误:https : //github.com/facebook/jest/issues/1700
这虽然有效:
describe('foo', () => {
it('should log and rethrow', async () => {
await expect(foo()).rejects.toEqual('error')
});
});
TA贡献1780条经验 获得超1个赞
当我不想使用toEqualor toBe(如其他正确答案)时,我会使用此代码。相反,我使用toBeTruthy.
async foo() {
throw "String error";
}
describe('foo', () => {
it('should throw a statement', async () => {
await expect(foo()).rejects.toBeTruthy();
});
});
添加回答
举报
