Testing & DebuggingLesson 77Free preview
Node Test Runner
This lesson is part of Node.js · All levels
Summary
This lesson discusses the built-in test runner Node.js, which is the node:test module available since Node 18. You can write a test with require('node:test') and an assertion with node:assert without additional dependencies. Also supports --testing on CLI, mocking, subtesting, and synchronous and async writing.
Key points
- Run the test with the node --test or node --test '*.test.js'.
- Node:test provides test(), describe(), it(), beforeEach(), and other hooks.
- Assertion uses node:assert or node:assert/strict (strictEqual, deepStrictEqual, rejects).
- Test async is written with async/await; a failure promise will be considered a failed test.
- Support mocking (mock.method, timers) and coverage through --experimental-test-coverage.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.