Testing with node:test
9 steps in 5 sets of JavaScript.
node:test, which arrived in the standard library and removed the need for a testing framework in a lot of projects. Writing tests, async and hooks, mocks and fake timers, and filtering what runs.
Nine steps, no dependencies, and it runs with the node you already have.
Writing tests
- node:testThe runner is built in: a test function and the assert module.
- describe and itNesting groups the output and shares setup between related cases.
Async & hooks
- Async testsReturn a promise or take a callback; the runner waits either way.
- Hooksbefore and after run once; the each variants run per test.
Mocks & time
- Mockst.mock.fn records calls; t.mock.method replaces one on an object.
- Faking timeMock timers make a delay instant and deterministic.
Selecting
- Skipping and focusingskip, todo and only, plus the conditional forms.
- The assert moduleDeep equality, throws, and the strict variants you should prefer.
Encore
- test-suite.jsA whole test file: suites, hooks, table cases, mocks and fake timers.