Skip to content

Latest commit

 

History

History
68 lines (50 loc) · 1.97 KB

no-settled-after-test-helper.md

File metadata and controls

68 lines (50 loc) · 1.97 KB

ember/no-settled-after-test-helper

💼 This rule is enabled in the ✅ recommended config.

🔧 This rule is automatically fixable by the --fix CLI option.

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.

Rule Details

This rule warns about cases where await settled() is used right after a call to a test helper function that already calls settled() internally (or settled() itself).

Examples

Examples of incorrect code for this rule:

test('...', async function (assert) {
  await click('.foo');
  await settled();
});
test('...', async function (assert) {
  await fillIn('.foo');
  await settled();
});
test('...', async function (assert) {
  await settled();
  await settled();
});

Examples of correct code for this rule:

test('...', async function (assert) {
  await waitFor('.foo');
  await settled();
});

Migration

References