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();
});
});
添加回答
舉報
