Skip to content

Latest commit

 

History

History
66 lines (47 loc) · 1.47 KB

prefer-ember-test-helpers.md

File metadata and controls

66 lines (47 loc) · 1.47 KB

prefer-ember-test-helpers

✅ The "extends": "plugin:ember/recommended" property in a configuration file enables this rule.

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