Mistake: Missing await
Find the Mistake Medium
Question
What is wrong with this async test?
Code
test('async test', () => {
const result = fetchData();
expect(result).toBe('data');
});
Hint
fetchData returns a Promise, not the resolved value.
Explanation
The mistake is not awaiting the async call. fetchData() returns a Promise, not the resolved value. The assertion compares a Promise to 'data', which will always fail. The fix: make the callback async and add await: test('async test', async () => { const result = await fetchData(); expect(result).toBe('data'); });.
Related Resources
Related Lessons
- Async Testing
Testing asynchronous code.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.