@zanzibar-ts/testkit
v0.1.1
Published
Four typed, function-style assertions over node:assert/strict — assertEquals, assert (narrowing), assertThrows, assertRejects. Zero dependencies; works in any test runner
Maintainers
Readme
@zanzibar-ts/testkit
Four typed, function-style assertions over Node's node:assert/strict: assertEquals (deep
structural equality), assert (a narrowing truthiness assertion), assertThrows, and
assertRejects. Zero dependencies, runner-agnostic (vitest, node:test, anything that runs a
function — failures are ordinary AssertionErrors).
It is the assertion vocabulary of the zanzibar-ts test
suites, published standalone. Use it if you prefer plain calls — assertEquals(actual, expected) —
over matcher chains.
import { deepStrictEqual } from 'node:assert/strict';
import { assert, assertEquals, assertRejects, assertThrows } from '@zanzibar-ts/testkit';
// deep structural equality:
assertEquals({ ok: true, value: [1, 2] }, { ok: true, value: [1, 2] });
// truthiness that NARROWS — after the assert, `maybe` is typed `string`:
const maybe: string | undefined = ['a'].at(0);
assert(maybe !== undefined, 'expected a value');
assertEquals(maybe.toUpperCase(), 'A');
// throws/rejects: assert the class, optionally a message substring, and get the error back typed:
const err = assertThrows(
() => {
throw new RangeError('depth 300 exceeds the cap');
},
RangeError,
'exceeds the cap',
);
assertEquals(err instanceof RangeError, true);
await assertRejects(() => Promise.reject(new Error('boom')), Error, 'boom');
// it IS node:assert underneath — same failure type (AssertionError), same semantics:
assertEquals(deepStrictEqual.name, 'deepStrictEqual');License
MIT
