Skip to content

Latest commit

 

History

History
77 lines (56 loc) · 1.65 KB

resolve-async.md

File metadata and controls

77 lines (56 loc) · 1.65 KB

Require that all async calls should be resolved in tests

Asynchronous operations on QUnit tests should be resolved within the scope of the test to maximize readability and maintainability. Also, if there are more async setup calls than async resolution calls, the test runner will hang, so this rule also helps to ensure correctness in test files.

Rule Details

The following patterns are considered warnings:

QUnit.test("Test name", function () {
    QUnit.stop();
});

QUnit.asyncTest("Test name", function () {
});

QUnit.test("Test name", function () {
    QUnit.stop();
    QUnit.stop();
    QUnit.start();
});

QUnit.test("Test name", function () {
    QUnit.stop(2);
    QUnit.start();
});

QUnit.test("Test name", function (assert) {
    var done = assert.async();
});

QUnit.test("Test name", function (assert) {
    var done1 = assert.async();
    var done2 = assert.async();
    done1();
});

The following patterns are not warnings:

QUnit.test("Test name", function () {
    QUnit.stop();
    QUnit.start();
});

QUnit.test("Test name", function (assert) {
    var done = assert.async();
    done();
});

QUnit.test("Test name", function (assert) {
    var done1 = assert.async();
    var done2 = assert.async();
    done1();
    done2();
});

When Not to Use It

This rule should generally not be disabled, but if you tend to put most of your async setup or resolution in common functions, this rule will raise warnings unnecessarily and can be disabled.

Further Reading