I am facing an issue while testing asynchronous actions using Jest. Currently, my test is passing when it should actually fail.
describe('Asynchronous Code', () => {
it('should execute promise', () => {
console.log(1);
someFunctionThatReturnsAPromise()
.then(() => {
console.log(2);
expect(true).toBeFalsy();
console.log(3);
});
console.log(4);
});
});
After running npm test
, the output shows:
PASS __tests__/Async.test.js
● Console
console.log __tests__/Async.test.js:3
1
console.log static-content-test/react/actions/DashboardActions.test.js:6
2
console.log static-content-test/react/actions/DashboardActions.test.js:10
4
Although the test passes, console.log(3)
is not executed as expected due to the failed assertion of true
being falsy.
I am seeking guidance on how to make Jest recognize expectations within async callbacks properly.