Jest 中的以下测试不应通过:
const targetFile = require("../targetFile.js");
fetch = jest.fn(() => Promise.resolve('file scoped default value'));
test('diffFileFetch', () => {
fetch.mockImplementation(() => new Promise((resolve, reject) => {
resolve('wrong value');
}));
targetFile.diffFileFetch()
.then(async data => {
await expect(data).toEqual('correct value');
})
.catch(e => console.log(e, `=====e=====`));
});
catch 块触发但测试仍然通过。这是什么原因,应该如何解决?
PASS
views/admin/__tests__/CurrentCouponListingSection.test.js
✓ diffFileFetch (6ms)
console.log views/admin/__tests__/testFile.test.js:59
{ Error: expect(received).toEqual(expected) // deep equality
Expected: "correct value"
Received: "wrong value"
at targetFile.diffFileFetch.then (/var/www/html/wptest2/wp-content/plugins/fvc/views/admin/__tests__/testFile.test.js:58:1)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
matcherResult:
{ actual: 'wrong value',
expected: 'correct value',
message: [Function],
name: 'toEqual',
pass: false } } '=====e====='
也试过
从 .then() 中删除 async/await。没有不同。
慕的地8271018
相关分类