qunit/no-throws-string

February 7, 2026 ยท View on GitHub

๐Ÿ“ Disallow assert.throws() with block, string, and message args.

๐Ÿ’ผ This rule is enabled in the โœ… recommended config.

QUnit 2.0 has deprecated the assert.throws(block, string, message) form of assert.throws(). This rule can be used to flag uses of the deprecated form and convert them to use a regular expression or some other predicate.

Rule Details

The following patterns are considered warnings:


QUnit.test('test', function (assert) {
    assert.throws(function () {
        // code
    }, "error message", "An error should have been thrown");
});

The following patterns are not warnings:


QUnit.test('test', function (assert) {
    assert.throws(function () {
        // code
    }, /error message/, "An error should have been thrown");
});

QUnit.test('test', function (assert) {
    assert.throws(function () {
        // code
    }, "An error should have been thrown");
});

QUnit.test('test', function (assert) {
    assert.throws(function () {
        // code
    }, function (err) { return true; }, "An error should have been thrown");
});

When Not To Use It

This rule can be safely disabled if you are not using QUnit 2.0.

Further Reading