class Assert

The assertion object passed to every test callback and lifecycle hook.

Every test callback receives an instance of Assert as its first argument. All assertion methods throw an AssertionError on failure, which the test runner catches and reports.

Examples

Example 1

import { module, test } from "qunitx";

module("Math", () => {
  test("addition", (assert) => {
    assert.equal(1 + 1, 2);
    assert.strictEqual(typeof 42, "number");
  });
});

Static Properties

AssertionError: AssertionErrorConstructor
QUnit: QUnitObject
inspect: InspectFn

Properties

test: TestState

Methods

async(): () => void

Returns a done callback for callback-style async tests. The test will not finish until every done callback returned by async() has been called.

For async/await tests prefer async (assert) => { ... } directly.

deepEqual(
actual: unknown,
expected: unknown,
message?: string
): void

Asserts deep equality between actual and expected using recursive structural comparison. Handles nested objects, arrays, Date, RegExp, and more.

equal(
actual: unknown,
expected: unknown,
message?: string
): void

Asserts that actual == expected (loose equality, allows type coercion).

Prefer Assert.prototype.strictEqual for most comparisons. Use Assert.prototype.notEqual for the inverse.

expect(number: number): void

Sets the number of assertions expected to run in the current test. The test fails if a different number of assertions actually ran.

false(
state: unknown,
message?: string
): void

Asserts that state === false (strict boolean false).

notDeepEqual(
actual: unknown,
expected: unknown,
message?: string
): void

Asserts that actual and expected are NOT deeply equal. Inverse of Assert.prototype.deepEqual.

notEqual(
actual: unknown,
expected: unknown,
message?: string
): void

Asserts that actual != expected (loose inequality). Inverse of Assert.prototype.equal.

notOk(
state: unknown,
message?: string
): void

Asserts that state is falsy.

notPropContains(
actual: unknown,
expected: unknown,
message?: string
): void

Asserts that actual does NOT contain all own enumerable properties from expected with matching values. Inverse of Assert.prototype.propContains.

notPropEqual(
actual: unknown,
expected: unknown,
message?: string
): void

Asserts that actual and expected do NOT have the same own enumerable properties and values. Inverse of Assert.prototype.propEqual.

notStrictEqual(
actual: unknown,
expected: unknown,
message?: string
): void

Asserts that actual !== expected (strict inequality). Inverse of Assert.prototype.strictEqual.

ok(
state: unknown,
message?: string
): void

Asserts that state is truthy.

propContains(
actual: unknown,
expected: unknown,
message?: string
): void

Asserts that actual contains all own enumerable properties from expected with matching values. Extra properties on actual are allowed and ignored.

propEqual(
actual: unknown,
expected: unknown,
message?: string
): void

Asserts that actual and expected have the same own enumerable properties and values. Prototype methods are ignored; only own properties are compared.

pushResult(resultInfo?: PushResultInfo): this

Pushes a custom assertion result. Fails the test if resultInfo.result is falsy. Throws an AssertionError on failure.

Useful for building custom assertion helpers.

rejects(
promise: unknown,
expectedInput?: unknown,
assertionMessage?: string
): Promise<void>

Asserts that a promise rejects. Optionally validates the rejection reason against a string (message substring), RegExp (message pattern), or constructor (instanceof check). For synchronous throws use Assert.prototype.throws.

step(message: string): void

Records a named step. Use with Assert.prototype.verifySteps to assert that a sequence of steps occurred in the right order.

strictEqual(
actual: unknown,
expected: unknown,
message?: string
): void

Asserts that actual === expected (strict equality, no type coercion).

throws(
blockFn: unknown,
expectedInput?: unknown,
assertionMessage?: string
): void

Asserts that blockFn throws an exception. Optionally validates the thrown error against a string (message substring), RegExp (message pattern), or constructor (instanceof check). For async functions use Assert.prototype.rejects.

timeout(number: number): void

Sets the number of milliseconds after which the current test will fail if not yet complete.

true(
state: unknown,
message?: string
): void

Asserts that state === true (strict boolean true).

verifySteps(
steps: string[],
message?: string
): void

Asserts that the steps recorded via Assert.prototype.step match the given array, then clears the recorded steps.

waitForAsyncOps(): Promise<void[]>