ant to test the following module index.ts
async function theFunctionFail() {
return await fail();
}
async function theFunctionSucceed() {
return await succeed();
}
async function fail() {
throw new Error();
}
async function succeed() {
return a;
}
export { theFunctionFail, theFunctionSucceed };
using a test index.test.ts
import { theFunctionFail, theFunctionSucceed } from ../index;
it('theFunctionFail', () => {
expect(theFunctionFail()).rejects;
});
What does the UnhandledPromiseRejectionWarning
in the output
(node:10515) UnhandledPromiseRejectionWarning: Error
(node:10515) 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:10515) [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 src/__tests__/index.test.ts
✓ theFunctionFail (6ms)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 1.806s
Ran all test suites.
refer to? Wrapping expect(theFunctionFail()).rejects
in a try-catch(err)
block doesn't avoid the warning which I consider worth fixing.
Why don't the test fail?/How can I make the tests fail? If my test discovered a severe flaw, it shouldn't succeed in my understanding.
I'm using Typescript and Jest 24.7.1 with react-scripts
.