Skip to content

Latest commit

 

History

History
68 lines (48 loc) · 1.55 KB

prefer-ember-test-helpers.md

File metadata and controls

68 lines (48 loc) · 1.55 KB

ember/prefer-ember-test-helpers

💼 This rule is enabled in the ✅ recommended config.

This rule ensures the correct Ember test helper is imported when using methods that have a native window counterpart.

There are currently 3 Ember test helper methods that have a native window counterpart:

  • blur
  • find
  • focus

If these methods are not properly imported from Ember's test-helpers suite, and the native window method version is used instead, any intended asynchronous functions won't work as intended, which can cause tests to fail silently.

Examples

Examples of incorrect code for this rule:

test('foo', async (assert) => {
  await blur('.some-element');
});
test('foo', async (assert) => {
  await find('.some-element');
});
test('foo', async (assert) => {
  await focus('.some-element');
});

Examples of correct code for this rule:

import { blur } from '@ember/test-helpers';

test('foo', async (assert) => {
  await blur('.some-element');
});
import { find } from '@ember/test-helpers';

test('foo', async (assert) => {
  await find('.some-element');
});
import { focus } from '@ember/test-helpers';

test('foo', async (assert) => {
  await focus('.some-element');
});

References