Skip to content

Latest commit

 

History

History
53 lines (36 loc) · 1.76 KB

no-assert-ok-find.md

File metadata and controls

53 lines (36 loc) · 1.76 KB

Disallow usage of assert.ok(find(...)) as it will always pass (square/no-assert-ok-find)

💼 This rule is enabled in the 🔥 ember config.

💡 This rule is manually fixable by editor suggestions.

Ember's old built-in find('.selector') acceptance test helper function always returns an array, even when no elements match. As a result, assert.ok(find('.selector')) will always pass, even if no elements are found, as an empty array is still truthy.

Note: find from @ember/test-helpers does not have this problem.

Rule Details

This rule disallows the aforementioned test assertion.

Examples

Examples of incorrect code for this rule:

test('the element exists', function (assert) {
  assert.ok(find('.selector'));
});

Examples of correct code for this rule:

test('the element exists', function (assert) {
  assert.equal(find('.selector').length, 1);
});
test('the element exists', function (assert) {
  assert.dom('.selector').exists(); // qunit-dom
});
import { find } from '@ember/test-helpers';

test('the element exists', function (assert) {
  assert.ok(find('.selector'));
});

References