1. For Promise resolves:
test cases using "xxx.resolves", always resolves (pass the test) even if the promise is "reject".
To verify the bug, change this line
).rejects.toThrow(ForbiddenError)
to ).resolves and the test would still pass.
Solution: need to change "resolves" to "resolves.not.toThrow()"
2. Test async function with jest
to use jest to test the promise returned from an async function foo():
correct format is:
it('xxxxx', async () => {
await expect( foo() ).resolves.not.toThrow()
})
the old code will not return a promise by putting await ahead of foo()
refer to: jestjs.io/docs/next/a…
stackoverflow.com/questions/5…