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. -
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: 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(): 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(): Promise<void>promise: unknown,expectedInput?: unknown,assertionMessage?: 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(): voidblockFn: unknown,expectedInput?: unknown,assertionMessage?: 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.
-
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. - waitForAsyncOps(): Promise<void[]>
Thrown when an assertion fails. Extends Deno's built-in AssertionError
so it integrates cleanly with Deno's test runner output.
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.
| ((
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 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.
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 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).
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).
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.
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.
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.
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.
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 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.
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.
The default export provides the full QUnitX API as a single object.