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

`node:test` provides [Node's test runner API](https://nodejs.org/api/test.html) (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);
  });
});
```

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

## 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

- [TypeScript tests](https://elide.help/docs/code-samples#typescript-tests)

<!-- api-reference:start c3c2a6313f8a -->
## Reference

**Status:** Partial · Not measured · since 1.1.0

### Exports

| Export | Kind | Status | Notes |
| --- | --- | --- | --- |
| `test()` | function | Full | Define and run a test case |
| `it()` | function | Full | Alias for test() |
| `describe()` | function | Full | Group tests into a suite |
| `suite()` | function | Full | Alias for describe() |
| `before()` | function | Full | Register a function to run before all tests in the current suite |
| `after()` | function | Full | Register a function to run after all tests in the current suite |
| `beforeEach()` | function | Full | Register a function to run before each test in the current suite |
| `afterEach()` | function | Full | Register a function to run after each test in the current suite |
| `mock` | property | Full | The mock object for creating spies and mocking timers |

### Not implemented

`expectFailure`, `getTestContext`.
<!-- api-reference:end -->
