QUnitX — universal test library that runs the same test file in Node.js, Deno, and browser.
Wraps QUnit's assertion API over each runtime's native BDD test runner so you only write your tests once.
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.