Skip to content

node:test

How Elide supports Node's test runner API: tests, suites, hooks and mocks run with elide test; run(), mock.module() and snapshots are unavailable.

On this page

node:test provides Node’s test runner API (tests, suites, hooks, test context, and mocks). Run test files with elide test.

Example

js
// math.test.mjs
import assert from "node:assert/strict";
import { describe, it, mock } from "node:test";

describe("math", () => {
  it("adds", () => {
    assert.equal(1 + 2, 3);
  });

  it("calls the callback once", () => {
    const callback = mock.fn();
    [1].forEach(callback);
    assert.equal(callback.mock.callCount(), 1);
  });
});
utf-8 · js · Lines: 15

elide test ./math.test.mjs prints:

text
math.test.mjs
✓ math > adds [1ms]
✓ math > calls the callback once

 2 pass
 0 skip
 0 fail
Ran 2 tests across one file. (0.01s)
utf-8 · text · Lines: 8

Differences from Node

  • elide run registers tests without running them and prints the elide test command to use.
  • run(), mock.module(), and the snapshot serializer setters throw ERR_METHOD_NOT_IMPLEMENTED.
  • Snapshot assertions are not available.

Samples

Reference

Status: Partial · Not measured · since 1.1.0

Exports

ExportKindStatusNotes
test()functionFullDefine and run a test case
it()functionFullAlias for test()
describe()functionFullGroup tests into a suite
suite()functionFullAlias for describe()
before()functionFullRegister a function to run before all tests in the current suite
after()functionFullRegister a function to run after all tests in the current suite
beforeEach()functionFullRegister a function to run before each test in the current suite
afterEach()functionFullRegister a function to run after each test in the current suite
mockpropertyFullThe mock object for creating spies and mocking timers

Not implemented

expectFailure, getTestContext.

Was this page helpful?