QUnitX — universal test library that runs the same test file in Node.js, Deno, and browser.
Example 1
Example 1
// math_test.js import { module, test } from "qunitx"; module("Math", (hooks) => { hooks.beforeEach(function () { this.numbers = [1, 2, 3]; }); test("addition", function (assert) { assert.equal(this.numbers.reduce((sum, n) => sum + n, 0), 6); }); test("async", async (assert) => { const n = await Promise.resolve(42); assert.strictEqual(n, 42); }); });
Both runtimes install it under the same name, so that one file runs on either. In a Deno project:
deno add qunitx
In a Node project:
npm install --save-dev qunitx
Then run it with whichever runner you have:
deno test math_test.js node --test math_test.js
Example 2
Example 2
// The same test written with the BDD aliases — describe and it are the same // function objects as module and test, so everything above applies unchanged. import { describe, it } from "qunitx"; describe("Math", (hooks) => { hooks.beforeEach(function () { this.numbers = [1, 2, 3]; }); it("addition", function (assert) { assert.equal(this.numbers.reduce((sum, n) => sum + n, 0), 6); }); it("async", async (assert) => { const n = await Promise.resolve(42); assert.strictEqual(n, 42); }); });
describe.skip, it.skip, it.todo, runtime options, and nesting all behave
identically to their module / test counterparts, and the commands above are
unchanged.
The assertion object passed to every test callback and lifecycle hook.
- AssertionError: AssertionErrorConstructor
- QUnit: QUnitObject
-
async(): () => void
Returns a
donecallback for callback-style async tests. The test will not finish until everydonecallback returned byasync()has been called. -
closeTo(): voidactual: number,expected: number,delta: number,message?: string
Asserts that
actualis withindeltaofexpected, inclusive: for numbers that floating-point arithmetic makes almost, but not exactly, equal. -
deepEqual(): voidactual: unknown,expected: unknown,message?: string
Asserts deep equality between
actualandexpectedusing recursive structural comparison. Handles nested objects, arrays,Date,RegExp, and more. -
equal(): voidactual: unknown,expected: unknown,message?: string
Asserts that
actual == expected(loose equality, allows type coercion). -
expect(): number | undefined
Returns the number of assertions set with
assert.expect(number)so far, if any. -
false(): voidstate: unknown,message?: string
Asserts that
state === false(strict boolean false). - inspect: InspectFn
-
notDeepEqual(): voidactual: unknown,expected: unknown,message?: string
Asserts that
actualandexpectedare NOT deeply equal. Inverse ofAssert.prototype.deepEqual. -
notEqual(): voidactual: unknown,expected: unknown,message?: string
Asserts that
actual != expected(loose inequality). Inverse ofAssert.prototype.equal. -
notOk(): voidstate: unknown,message?: string
Asserts that
stateis falsy. -
notPropContains(): voidactual: unknown,expected: unknown,message?: string
Asserts that
actualdoes NOT contain all own enumerable properties fromexpectedwith matching values. Inverse ofAssert.prototype.propContains. -
notPropEqual(): voidactual: unknown,expected: unknown,message?: string
Asserts that
actualandexpecteddo NOT have the same own enumerable properties and values. Inverse ofAssert.prototype.propEqual. -
notStrictEqual(): voidactual: unknown,expected: unknown,message?: string
Asserts that
actual !== expected(strict inequality). Inverse ofAssert.prototype.strictEqual. -
ok(): voidstate: unknown,message?: string
Asserts that
stateis truthy. -
propContains(): voidactual: unknown,expected: unknown,message?: string
Asserts that
actualcontains all own enumerable properties fromexpectedwith matching values. Extra properties onactualare allowed and ignored. -
propEqual(): voidactual: unknown,expected: unknown,message?: string
Asserts that
actualandexpectedhave 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.resultis falsy. Throws anAssertionErroron failure. -
rejects<E>(): Promise<E>promise: PromiseLike<unknown>,expected: new (...args: never[]) => E,message?: string
Asserts that a promise rejects. Optionally validates the rejection reason against a string (message substring), RegExp (message pattern), or constructor (
instanceofcheck). For synchronous throws useAssert.prototype.throws. -
step(message: string): void
Records a named step. Use with
Assert.prototype.verifyStepsto assert that a sequence of steps occurred in the right order. -
strictEqual(): voidactual: unknown,expected: unknown,message?: string
Asserts that
actual === expected(strict equality, no type coercion). - test: TestState
-
throws<E>(): EblockFn: () => unknown,expected: new (...args: never[]) => E,message?: string
Asserts that
blockFnthrows an exception. Optionally validates the thrown error against a string (message substring), RegExp (message pattern), or constructor (instanceofcheck). For async functions useAssert.prototype.rejects. -
timeout(number: number): void
Sets the number of milliseconds after which the current test will fail if not yet complete. Overrides the default from
config.testTimeout(3000) for this test;0requires the test to finish synchronously. -
true(): voidstate: unknown,message?: string
Asserts that
state === true(strict boolean true). -
verifySteps(): voidsteps: string[],message?: string
Asserts that the steps recorded via
Assert.prototype.stepmatch the given array, then clears the recorded steps. Counts as one assertion, however many steps it checks. - waitForAsyncOps(): Promise<void[]>
Thrown when an assertion fails. Extends Deno's built-in AssertionError
so it integrates cleanly with Deno's test runner output.
Runs only this module, and any other only module or test: every other test is
skipped. Equivalent to QUnit.module.only, and to passing { only: true }.
Deno runs only these, and then fails the run on purpose, so that an only is
not committed by accident.
Skips all tests inside a module. Equivalent to QUnit.module.skip.
The module is registered as ignored by Deno's runner; no test bodies run.
Marks all tests inside a module as todo. Equivalent to QUnit.module.todo.
The module is registered as ignored by Deno's runner; no test bodies run.
Deno has no native "todo module" concept, so this maps to ignore.
| ((
Defines an individual test within a module for Deno's BDD test runner.
| ((
Defines an individual test within a module for Deno's BDD test runner.
Defines one test per case of dataset, each receiving its case as data.
Equivalent to QUnit.test.each, and names the cases as it does: name [value] for a
short string, name [index: value] for other primitives, name [index] otherwise,
and name [key] for an object dataset.
Defines one test per case of dataset, each receiving its case as data.
Equivalent to QUnit.test.each, and names the cases as it does: name [value] for a
short string, name [index: value] for other primitives, name [index] otherwise,
and name [key] for an object dataset.
Defines one test per case of dataset, each receiving its case as data.
Equivalent to QUnit.test.each, and names the cases as it does: name [value] for a
short string, name [index: value] for other primitives, name [index] otherwise,
and name [key] for an object dataset.
Defines one test per case of dataset, each receiving its case as data.
Equivalent to QUnit.test.each, and names the cases as it does: name [value] for a
short string, name [index: value] for other primitives, name [index] otherwise,
and name [key] for an object dataset.
Defines one test per case of dataset, each receiving its case as data.
Equivalent to QUnit.test.each, and names the cases as it does: name [value] for a
short string, name [index: value] for other primitives, name [index] otherwise,
and name [key] for an object dataset.
Defines one test per case of dataset, each receiving its case as data.
Equivalent to QUnit.test.each, and names the cases as it does: name [value] for a
short string, name [index: value] for other primitives, name [index] otherwise,
and name [key] for an object dataset.
Runs only this module, and any other only module or test: every other test is
skipped. Equivalent to QUnit.module.only, and to passing { only: true }.
Deno runs only these, and then fails the run on purpose, so that an only is
not committed by accident.
Runs only this module, and any other only module or test: every other test is
skipped. Equivalent to QUnit.module.only, and to passing { only: true }.
Deno runs only these, and then fails the run on purpose, so that an only is
not committed by accident.
Runs only this module, and any other only module or test: every other test is
skipped. Equivalent to QUnit.module.only, and to passing { only: true }.
Deno runs only these, and then fails the run on purpose, so that an only is
not committed by accident.
Runs only this module, and any other only module or test: every other test is
skipped. Equivalent to QUnit.module.only, and to passing { only: true }.
Deno runs only these, and then fails the run on purpose, so that an only is
not committed by accident.
Runs only this module, and any other only module or test: every other test is
skipped. Equivalent to QUnit.module.only, and to passing { only: true }.
Deno runs only these, and then fails the run on purpose, so that an only is
not committed by accident.
Runs only this module, and any other only module or test: every other test is
skipped. Equivalent to QUnit.module.only, and to passing { only: true }.
Deno runs only these, and then fails the run on purpose, so that an only is
not committed by accident.
Skips all tests inside a module. Equivalent to QUnit.module.skip.
The module is registered as ignored by Deno's runner; no test bodies run.
Skips all tests inside a module. Equivalent to QUnit.module.skip.
The module is registered as ignored by Deno's runner; no test bodies run.
Skips all tests inside a module. Equivalent to QUnit.module.skip.
The module is registered as ignored by Deno's runner; no test bodies run.
Skips all tests inside a module. Equivalent to QUnit.module.skip.
The module is registered as ignored by Deno's runner; no test bodies run.
Skips all tests inside a module. Equivalent to QUnit.module.skip.
The module is registered as ignored by Deno's runner; no test bodies run.
Skips all tests inside a module. Equivalent to QUnit.module.skip.
The module is registered as ignored by Deno's runner; no test bodies run.
Marks all tests inside a module as todo. Equivalent to QUnit.module.todo.
The module is registered as ignored by Deno's runner; no test bodies run.
Deno has no native "todo module" concept, so this maps to ignore.
Marks all tests inside a module as todo. Equivalent to QUnit.module.todo.
The module is registered as ignored by Deno's runner; no test bodies run.
Deno has no native "todo module" concept, so this maps to ignore.
Marks all tests inside a module as todo. Equivalent to QUnit.module.todo.
The module is registered as ignored by Deno's runner; no test bodies run.
Deno has no native "todo module" concept, so this maps to ignore.
Marks all tests inside a module as todo. Equivalent to QUnit.module.todo.
The module is registered as ignored by Deno's runner; no test bodies run.
Deno has no native "todo module" concept, so this maps to ignore.
Marks all tests inside a module as todo. Equivalent to QUnit.module.todo.
The module is registered as ignored by Deno's runner; no test bodies run.
Deno has no native "todo module" concept, so this maps to ignore.
Marks all tests inside a module as todo. Equivalent to QUnit.module.todo.
The module is registered as ignored by Deno's runner; no test bodies run.
Deno has no native "todo module" concept, so this maps to ignore.
Defines one test per case of dataset, each receiving its case as data.
Equivalent to QUnit.test.each, and names the cases as it does: name [value] for a
short string, name [index: value] for other primitives, name [index] otherwise,
and name [key] for an object dataset.
Lifecycle hooks available inside a module() callback.
-
after(fn: HookFn<A>): void
Runs once after the last test in the module.
-
afterEach(fn: HookFn<A>): void
Runs after each test in the module.
-
before(fn: HookFn<A>): void
Runs once before the first test in the module.
-
beforeEach(fn: HookFn<A>): void
Runs before each test in the module.
Result object passed to Assert.prototype.pushResult.
-
actual: unknown
The actual value produced by the code under test.
-
expected: unknown
The expected value.
-
message: string
Human-readable description of the assertion.
-
result: boolean
Whether the assertion passed (
true) or failed (false).
A lifecycle hook callback that receives an Assert instance and a meta object with the shared context.
A test body: receives an Assert instance and a meta object naming the test, its runtime options, and the shared context.
Runner settings for Node.js and Deno, named after the QUnit.config keys they mirror.
Each test reads them as it starts, so a change applies to the tests that start after it.
The default export provides the full QUnitX API as a single object.
Hooks for every test in the run, in every module: QUnit.hooks for Node.js and Deno.
A global beforeEach runs before any module's, and a global afterEach after all of
them. Each receives (assert, { context }), with the test's context as this.
Runs only this test, and any other only test or module: every other test is skipped.
Equivalent to QUnit.test.only, and to passing { only: true }.
Deno runs only these, and then fails the run on purpose, so that an only is
not committed by accident.
Runs only this test, and any other only test or module: every other test is skipped.
Equivalent to QUnit.test.only, and to passing { only: true }.
Deno runs only these, and then fails the run on purpose, so that an only is
not committed by accident.
Runs only this test, and any other only test or module: every other test is skipped.
Equivalent to QUnit.test.only, and to passing { only: true }.
Deno runs only these, and then fails the run on purpose, so that an only is
not committed by accident.
Runs only this test, and any other only test or module: every other test is skipped.
Equivalent to QUnit.test.only, and to passing { only: true }.
Deno runs only these, and then fails the run on purpose, so that an only is
not committed by accident.
Runs only this test, and any other only test or module: every other test is skipped.
Equivalent to QUnit.test.only, and to passing { only: true }.
Deno runs only these, and then fails the run on purpose, so that an only is
not committed by accident.
Runs only this test, and any other only test or module: every other test is skipped.
Equivalent to QUnit.test.only, and to passing { only: true }.
Deno runs only these, and then fails the run on purpose, so that an only is
not committed by accident.
Registers a skipped test. Equivalent to QUnit.test.skip.
The test body is never executed; the test is reported as ignored by Deno's runner.
Registers a skipped test. Equivalent to QUnit.test.skip.
The test body is never executed; the test is reported as ignored by Deno's runner.
Registers a skipped test. Equivalent to QUnit.test.skip.
The test body is never executed; the test is reported as ignored by Deno's runner.
Registers a skipped test. Equivalent to QUnit.test.skip.
The test body is never executed; the test is reported as ignored by Deno's runner.
Registers a skipped test. Equivalent to QUnit.test.skip.
The test body is never executed; the test is reported as ignored by Deno's runner.
Registers a skipped test. Equivalent to QUnit.test.skip.
The test body is never executed; the test is reported as ignored by Deno's runner.
Registers a todo test. Equivalent to QUnit.test.todo.
The test body is never executed; the test is reported as ignored by Deno's runner
(Deno has no native todo concept).
Registers a todo test. Equivalent to QUnit.test.todo.
The test body is never executed; the test is reported as ignored by Deno's runner
(Deno has no native todo concept).
Registers a todo test. Equivalent to QUnit.test.todo.
The test body is never executed; the test is reported as ignored by Deno's runner
(Deno has no native todo concept).
Registers a todo test. Equivalent to QUnit.test.todo.
The test body is never executed; the test is reported as ignored by Deno's runner
(Deno has no native todo concept).
Registers a todo test. Equivalent to QUnit.test.todo.
The test body is never executed; the test is reported as ignored by Deno's runner
(Deno has no native todo concept).
Registers a todo test. Equivalent to QUnit.test.todo.
The test body is never executed; the test is reported as ignored by Deno's runner
(Deno has no native todo concept).
Runs only this test, and any other only test or module. Equivalent to test.only.
Deno runs only these, and then fails the run on purpose, so that an only is not
committed by accident.
Registers a skipped test. Equivalent to test.skip. The test body is never
executed and the test is reported as ignored by Deno's runner.
Runs only this test, and any other only test or module: every other test is skipped.
Equivalent to QUnit.test.only, and to passing { only: true }.
Deno runs only these, and then fails the run on purpose, so that an only is
not committed by accident.
Registers a skipped test. Equivalent to QUnit.test.skip.
The test body is never executed; the test is reported as ignored by Deno's runner.
Registers a todo test. Equivalent to QUnit.test.todo.
The test body is never executed; the test is reported as ignored by Deno's runner
(Deno has no native todo concept).
Registers a todo test. Equivalent to test.todo. The test body is never executed
and the test is reported as ignored by Deno's runner, which has no native todo concept.