default

QUnitX — universal test library that runs the same test file in Node.js, Deno, and browser.

Examples

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

// 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.

Classes

c
Assert(
module: ModuleState | null,
test?: TestState
)

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

c
AssertionError(object: AssertionErrorOptions)

Thrown when an assertion fails. Extends Deno's built-in AssertionError so it integrates cleanly with Deno's test runner output.

Functions

f
describe.onlyModule(
moduleName: string,
runtimeOptionsOrContent: object | ModuleContent,
moduleContent?: ModuleContent
): void

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.

f
describe.skipModule(
moduleName: string,
_moduleContent?: unknown
): void

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.

f
describe.todoModule(
moduleName: string,
_moduleContent?: unknown
): void

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.

f
it.eachTest<T>(
testName: string,
dataset: EachData<T>,
callback: EachCallback<Assert, T>
): void

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.

f
it.eachTest<T>(
testName: string,
dataset: EachData<T>,
callback: EachCallback<Assert, T>
): void

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.

f
it.eachTest<T>(
testName: string,
dataset: EachData<T>,
callback: EachCallback<Assert, T>
): void

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.

f
it.eachTest<T>(
testName: string,
dataset: EachData<T>,
callback: EachCallback<Assert, T>
): void

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.

f
it.eachTest<T>(
testName: string,
dataset: EachData<T>,
callback: EachCallback<Assert, T>
): void

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.

f
it.eachTest<T>(
testName: string,
dataset: EachData<T>,
callback: EachCallback<Assert, T>
): void

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.

f
module.onlyModule(
moduleName: string,
runtimeOptionsOrContent: object | ModuleContent,
moduleContent?: ModuleContent
): void

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.

f
module.onlyModule(
moduleName: string,
runtimeOptionsOrContent: object | ModuleContent,
moduleContent?: ModuleContent
): void

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.

f
module.onlyModule(
moduleName: string,
runtimeOptionsOrContent: object | ModuleContent,
moduleContent?: ModuleContent
): void

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.

f
module.onlyModule(
moduleName: string,
runtimeOptionsOrContent: object | ModuleContent,
moduleContent?: ModuleContent
): void

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.

f
module.onlyModule(
moduleName: string,
runtimeOptionsOrContent: object | ModuleContent,
moduleContent?: ModuleContent
): void

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.

f
module.onlyModule(
moduleName: string,
runtimeOptionsOrContent: object | ModuleContent,
moduleContent?: ModuleContent
): void

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.

f
module.skipModule(
moduleName: string,
_moduleContent?: unknown
): void

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.

f
module.skipModule(
moduleName: string,
_moduleContent?: unknown
): void

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.

f
module.skipModule(
moduleName: string,
_moduleContent?: unknown
): void

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.

f
module.skipModule(
moduleName: string,
_moduleContent?: unknown
): void

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.

f
module.skipModule(
moduleName: string,
_moduleContent?: unknown
): void

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.

f
module.skipModule(
moduleName: string,
_moduleContent?: unknown
): void

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.

f
module.todoModule(
moduleName: string,
_moduleContent?: unknown
): void

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.

f
module.todoModule(
moduleName: string,
_moduleContent?: unknown
): void

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.

f
module.todoModule(
moduleName: string,
_moduleContent?: unknown
): void

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.

f
module.todoModule(
moduleName: string,
_moduleContent?: unknown
): void

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.

f
module.todoModule(
moduleName: string,
_moduleContent?: unknown
): void

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.

f
module.todoModule(
moduleName: string,
_moduleContent?: unknown
): void

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.

f
test.eachTest<T>(
testName: string,
dataset: EachData<T>,
callback: EachCallback<Assert, T>
): void

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.

Interfaces

I
HooksObject

Lifecycle hooks available inside a module() callback.

I
PushResultInfo

Result object passed to Assert.prototype.pushResult.

Namespaces

N
describe

Additional properties on the describe function.

N
test

Additional properties on the test function.

Type Aliases

T
HookFn<A = unknown> = (
assert: A,
meta: { context: Record<string, unknown>; }
) => void | Promise<void>

A lifecycle hook callback that receives an Assert instance and a meta object with the shared context.

T
TestFn<A = unknown> = (
assert: A,
meta: { testName: string; options: unknown; context: Record<string, unknown>; }
) => void | Promise<unknown>

A test body: receives an Assert instance and a meta object naming the test, its runtime options, and the shared context.

Variables

v
config: { testTimeout: number; }

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.

v
hooks: { beforeEach(fn: HookFn<Assert>): void; afterEach(fn: HookFn<Assert>): void; }

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.

v
it.only: OnlyTest<Assert>

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.

v
it.only: OnlyTest<Assert>

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.

v
it.only: OnlyTest<Assert>

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.

v
it.only: OnlyTest<Assert>

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.

v
it.only: OnlyTest<Assert>

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.

v
it.only: OnlyTest<Assert>

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.

v
it.skip: SkipTest

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.

v
it.skip: SkipTest

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.

v
it.skip: SkipTest

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.

v
it.skip: SkipTest

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.

v
it.skip: SkipTest

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.

v
it.skip: SkipTest

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.

v
it.todo: TodoTest<Assert>

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).

v
it.todo: TodoTest<Assert>

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).

v
it.todo: TodoTest<Assert>

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).

v
it.todo: TodoTest<Assert>

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).

v
it.todo: TodoTest<Assert>

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).

v
it.todo: TodoTest<Assert>

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).

v
only: Test.only

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.

v
skip: Test.skip

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.

v
test.only: OnlyTest<Assert>

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.

v
test.skip: SkipTest

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.

v
test.todo: TodoTest<Assert>

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).

v
todo: Test.todo

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.