Async Test Not Awaiting Promise
Error message
Test finished without asserting — async function was not awaited
Quick summary
The test function returns before the async operation completes. Jest marks the test as passed without running the assertions, giving a false positive.
Why this happens
The test callback is not marked as async, so await cannot be used.
An async function call is missing the await keyword.
A Promise is not returned from the test callback.
Using .then() without returning the Promise from the test.
Minimal example
test('async test', () => {
const result = fetchData(); // missing await
expect(result).toBe('data'); // compares Promise to 'data'
});test('async test', async () => {
const result = await fetchData(); // properly awaited
expect(result).toBe('data');
});Add async to the callback and await the async call so Jest waits for it to complete.
How to diagnose
Check if the test callback function has the 'async' keyword.
Look for async function calls without 'await' before them.
Add console.log inside the .then() or after await to see if the code runs.
Use Jest's --verbose flag to see if the test finishes too quickly.
How to fix
Mark the test callback as async and add await: test('name', async () => { const result = await asyncFn(); ... })
Alternatively, return the Promise: test('name', () => { return asyncFn().then(result => { ... }); })
For callback-based async, use the done parameter: test('name', (done) => { asyncFn(() => { ...; done(); }); })
How to prevent
Always use async/await for async tests — it's the clearest pattern.
Enable Jest's expect.hasAssertions() to fail tests that don't assert.
Related Resources
Related Glossary
Related Lessons
- Async Testing
Testing asynchronous code.