Avoid using `settled()` after `ember-test-helpers`JS-P1000
The issue is raised where await settled()
is used right after a call to a test helper function that already calls settled()
internally (or settled()
itself).
It can be fixed by using the API of ember-test-waiters
when you want to call settled()
. It is an Ember addon to allow @ember/test-helpers
to manage asynchronous operations
Most of the test helper functions in @ember/test-helpers
call settled()
internally, which causes the test to wait until any effects of e.g. the click()
operation have settled. This means calling await settled()
after calling one of these test helpers is redundant and should not be necessary.
In some cases this pattern is mistakenly used to "wait a little more", which usually indicated a deeper root cause issue, like a race condition or missing test waiter somewhere. This pattern only works sometimes because it causes the test to continue on the next tick of the JS runloop, instead of continuing directly. It is highly recommended to fix the root cause in these cases instead of relying on such brittle workarounds.
Bad Practice
test('...', async function (assert) {
await click('.className');
await settled();
});
or
test('...', async function (assert) {
await fillIn('.className');
await settled();
});
Recommended
test('...', async function (assert) {
await waitFor('.className');
await settled();
});