Emberjs - How to test promises and other async behavior?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
Testing async behavior in Ember is much easier once you stop thinking in terms of manual promise plumbing and start using Ember’s test helpers correctly. Modern Ember testing is built around async and await, plus helpers that already know how to wait for rendering, timers, promises, and request-driven UI updates to settle.
Use Async Helpers Instead of Manual Timing
The main rule is simple: do not test async code with arbitrary delays such as setTimeout(..., 50). Ember’s @ember/test-helpers package already provides helpers that wait for the app to settle after interactions.
A rendering test might look like this:
click() already waits for the async work it triggers, and settled() is available when you want to be explicit.
Test the User-Visible Result, Not the Promise Itself
A common mistake is writing assertions about internal promise state. In Ember, the stronger test is usually about the DOM or public state after the async work completes.
For example, if a route loads data:
This is better than checking whether some route method returned a promise, because it verifies behavior the user actually depends on.
Waiting for Non-Standard Async Work
Sometimes the built-in settled state is not enough. For example, a third-party library may update state outside Ember’s usual tracking path. In those cases, use waitUntil or waitFor.
This is still better than sleeping for a guessed number of milliseconds. You wait for a real condition instead of hoping timing lines up.
Mock Network Requests
Async tests become reliable when the network is under your control. In Ember apps, Mirage is a common choice for that. A basic test could look like this:
Now the test is deterministic because the response shape and timing are defined by the test.
Older Patterns Versus Current Patterns
If you find examples using andThen, run, or deeply nested callbacks, check the Ember version before copying them. Older testing styles existed before the current async-helper model was standardized. In current Ember code, async and await with @ember/test-helpers are the baseline.
That shift matters because old tests often become flaky when mixed with modern helpers. Stay within one testing style.
Common Pitfalls
The most common mistake is using manual delays instead of waiting on a condition or using Ember’s async helpers. That creates flaky tests that pass locally and fail in CI.
Another issue is forgetting to await helper calls. If you write click('button') without await, the next assertion may run before the UI updates.
Tests also become brittle when they assert implementation details instead of observable results. Prefer checking rendered text, element presence, or tracked state exposed through the component.
Finally, if an async flow depends on HTTP, mock it. Real network traffic makes tests slower and less predictable.
Summary
- Modern Ember async tests should use
asyncandawaitwith@ember/test-helpers. - Helpers such as
visit,render, andclickalready wait for async work they trigger. - Use
settled,waitUntil, orwaitForwhen you need explicit control. - Test user-visible outcomes rather than internal promise objects.
- Avoid manual delays and old callback-heavy testing patterns.
Related reading
- Entity Framework async operation takes ten times as long to complete
- Entity Framework hangs when using async calls
- Error Cannot find module 'async_hooks' in NodeJs
- Error Cannot use 'async' on methods without bodies. How to force async child overrides?
- endsWith in JavaScript
- Error Cannot find module 'aws-sdk' in NodeJS AWS Lambda Function
- End to end integration test for multiple spring boot applications under Maven
- Error TestEngine with ID 'junit-vintage' failed to discover tests with Spring Boot 2.2
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.