即使断言失败,笑话测试仍会通过

时间:2018-10-09 08:42:12

标签: async-await jestjs

我正在使用笑话测试异步功能。该函数中的代码位于try catch块中,发现并处理了错误,类似于以下内容

export default async () => {
    try {
        await promisesAndThat();
    } catch (e) {
        // handle errors
    }
}

当我运行npm test时,异步函数将按预期方式引发错误,并将结果返回给玩笑,然后抱怨UnhandledPromiseRejectionWarning并在断言 but 无论如何,测试通过。请参阅下面的更多信息:

/home/app # npm test

> node-js-base@1.0.0 test /home/app
> jest

(node:77) UnhandledPromiseRejectionWarning: Error: expect(received).toBe(expected) // Object.is equality

Expected value to be:
"Invalid context"
Received:
"Invalid parameters"
(node:77) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:77) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
PASS  function/handler.test.js
✓ Should return true with valid parameters (8ms)
✓ Should return false with invalid parameters (4ms)

Test Suites: 1 passed, 1 total
Tests:       2 passed, 2 total
Snapshots:   0 total
Time:        1.276s
Ran all test suites.

有人知道这是怎么回事吗?

0 个答案:

没有答案