Performance: Testing async code
MEDIUM IMPACT
This affects test execution speed and responsiveness of test suites, impacting developer feedback loops.
test('fetch data', async () => { const data = await fetchData(); expect(data).toBeDefined(); });
test('fetch data', (done) => {
fetchData().then(data => {
expect(data).toBeDefined();
done();
});
});| Pattern | Test Runner Blocking | Flaky Tests | Execution Time | Verdict |
|---|---|---|---|---|
| Callback without wait | Blocks until timeout | High chance | Longer due to retries | [X] Bad |
| Async/await or returned promise | Non-blocking | Minimal | Faster and reliable | [OK] Good |