Skip to content

Latest commit

 

History

History
85 lines (48 loc) · 2.68 KB

no-ok-equality.md

File metadata and controls

85 lines (48 loc) · 2.68 KB

Disallow equality comparisons in assert.ok/assert.notOk (qunit/no-ok-equality)

💼 This rule is enabled in the ✅ recommended config.

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

Equality comparisons in assert.ok or assert.notOk calls are not valuable because if the assertion fails, QUnit cannot reveal any comparison information. Instead, developers should use assert.equal, assert.strictEqual, assert.notEqual, or assert.notStrictEqual to allow QUnit to track the expected and actual values and show a useful diff. This makes test output much easier to read.

Rule Details

The following patterns are considered warnings:

QUnit.test("Name", function (assert) { assert.ok(x === 1); });

QUnit.test("Name", function (assert) { assert.notOk(x === 1); });

QUnit.test("Name", function (assert) { assert.ok(x !== 1); });

QUnit.test("Name", function (assert) { assert.notOk(x !== 1); });

In addition, if { allowGlobals: true } option is on (the default), the following patterns are also considered warnings:

QUnit.test("Name", function () { ok(x === 1); });

QUnit.test("Name", function () { notOk(x === 1); });

QUnit.test("Name", function () { ok(x !== 1); });

QUnit.test("Name", function () { notOk(x !== 1); });

The previous patterns are not warnings if { allowGlobals: false } is passed in as an option.

The following patterns are not considered warnings:

QUnit.test("Name", function (assert) { assert.ok(x); });

QUnit.test("Name", function (assert) { assert.ok(x > 1); });

QUnit.test("Name", function (assert) { assert.ok(x < 1); });

QUnit.test("Name", function (assert) { assert.ok(x >= 1); });

QUnit.test("Name", function (assert) { assert.ok(x <= 1); });

QUnit.test("Name", function (assert) { assert.ok(x instanceof Number); });

Options

Name Description Type Default
allowGlobal Whether the rule should check global assertions. Boolean true

When Not to Use It

It is best to enable this rule, but since it is possible to test a codebase using equality comparisons in assert.ok and assert.notOk calls, this rule can be disabled if enabling it would be too much of a pain.

Further Reading