Skip to content

Latest commit

 

History

History
37 lines (22 loc) · 1.22 KB

no-conditional-assertions.md

File metadata and controls

37 lines (22 loc) · 1.22 KB

Disallow assertions within if statements or conditional expressions (qunit/no-conditional-assertions)

💼 This rule is enabled in the ✅ recommended config.

This rule aims to detect non-deterministic unit testing by looking for assertions in an if statement or conditional expression.

Most of the time, a unit test should know what it is testing and what assertions should be run for a given test. Conditional assertions suggest that the developer is not sure how the unit test should run, or else that the developer is unfamiliar with testing boolean conditions within an assertion.

If a test is uncertain due to environmental factors (e.g., if a test should only be run in a browser environment), then a conditional test should be used. This rule does not flag conditional tests.

Rule Details

The following patterns are considered warnings:

if (condition) {
    assert.ok(foo);
}

condition ? assert.ok(foo) : assert.notOk(foo);

The following patterns are not warnings:

if (condition) {
    QUnit.test("some test", function (assert) {
        assert.ok(true);
    });
}