test("loads the user", () => {
fetchUser(1).then((user) => {
expect(user.name).toBe("Ana");
});
});
The test returns before the promise settles, so Jest marks it passed without seeing the failed assertion
The test returns before the promise settles, so Jest marks it passed. Jest only waits for a promise if the test returns it, or if the test is async and awaits it. Here the callback returns undefined, so the test ends at once and never sees the failed assertion. Fix it with return fetchUser(1).then(...) or const user = await fetchUser(1). The option saying Jest ignores .then() assertions on purpose is wrong. Jest runs them, but only if it is still waiting.
Read more