# node:assert

> How Elide supports Node's `assert` and `assert/strict` modules: which assertions work, and where loose deep equality, the `Assert` class and error messages differ.

`node:assert` and `node:assert/strict` provide [Node's assertion functions](https://nodejs.org/api/assert.html),
from `ok` and `deepStrictEqual` to `throws`, `rejects`, `match` and `partialDeepStrictEqual`.

## Example

```js
// assert.mjs
import assert from "node:assert/strict";

assert.deepEqual({ ids: [1, 2] }, { ids: [1, 2] });
assert.throws(() => JSON.parse("{"), SyntaxError);
await assert.rejects(Promise.reject(new Error("nope")), /nope/);

try {
  assert.equal(1 + 1, 3);
} catch (error) {
  console.log(error.name, error.code, error.actual, error.expected);
}
```

`elide run assert.mjs` prints:

```text
AssertionError ERR_ASSERTION 2 3
```

## Differences from Node

- `assert.Assert` is not a constructor.
- Loose `deepEqual` treats `null` and `undefined` as different, and compares proxies differently.
- A symbol `message`, or a number as `expected` in `throws()`, raises `AssertionError` instead of
  `ERR_INVALID_ARG_TYPE`.
- `AssertionError.operator` holds the method name (`strictEqual`), not a symbol (`===`).

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

**Status:** Partial · 7 of 13 suite tests pass (53.8%) · since 1.1.0

### Exports

| Export | Kind | Status | Notes |
| --- | --- | --- | --- |
| `ok()` | function | Full | Tests if `value` is truthy |
| `equal()` | function | Full | Tests shallow equality between `actual` and `expected` using `==` |
| `notEqual()` | function | Full | Tests shallow inequality between `actual` and `expected` using `!=` |
| `strictEqual()` | function | Full | Tests strict equality between `actual` and `expected` using `===` |
| `notStrictEqual()` | function | Full | Tests strict inequality between `actual` and `expected` using `!==` |
| `deepEqual()` | function | Full | Tests for deep equality between `actual` and `expected` using abstract equality (`==`) for leaf comparisons |
| `deepStrictEqual()` | function | Full | Tests for deep strict equality between `actual` and `expected` using strict equality (`===`) for leaf… |
| `notDeepEqual()` | function | Full | Tests that `actual` is NOT deeply equal to `expected` (abstract equality) |
| `notDeepStrictEqual()` | function | Full | Tests that `actual` is NOT deeply strictly equal to `expected` |
| `throws()` | function | Full | Expects the function `fn` to throw an error |
| `doesNotThrow()` | function | Full | Asserts that the function `fn` does not throw an error |
| `rejects()` | function | Full | Awaits the `asyncFn` promise (or calls it if it's a function) and expects it to reject |
| `doesNotReject()` | function | Full | Awaits the `asyncFn` promise (or calls it if it's a function) and expects it NOT to reject |
| `fail()` | function | Full | Throws an AssertionError unconditionally |
| `ifError()` | function | Full | If `value` is truthy (not null/undefined/false), throws it |
| `match()` | function | Full | Expects `string` to match the regular expression `regexp` |
| `doesNotMatch()` | function | Full | Expects `string` NOT to match the regular expression `regexp` |

### Not implemented

`Assert`, `assert/strict.Assert`.

**Tests:** [node-api `node:assert`](https://github.com/elide-dev/testsuite/blob/main/reports/1.6.0%2B6e718933f/4cbcae6c33a8/node-api/node-api.md): 7 pass, 6 fail, 0 error, 1 skipped. Failing: `test-assert-async.js`, `test-assert-class-destructuring.js`, `test-assert-class.js`, `test-assert-deep.js`, `test-assert-esm-cjs-message-verify.js`, `test-assert.js`.
<!-- api-reference:end -->
