Understand the key terms of Node.js's built-in test runner — from importing node:test and writing describe/it blocks to mocking with mock.fn() and using --watch mode.
0 / 5 completed
1 / 5
How do you import the built-in test runner in Node.js without installing any package?
Node.js ships a built-in test runner accessible via import { test, describe, it } from 'node:test' (note the node: prefix). No npm install is required; it is available from Node 18+ and stabilised in Node 20.
2 / 5
Which module provides the assertion functions used with the Node.js test runner?
The node:assert module is the standard assertion library paired with the Node.js test runner. Functions like assert.strictEqual(), assert.deepStrictEqual(), and assert.throws() cover most testing needs without third-party dependencies.
3 / 5
How do you create a mock function using the Node.js built-in test runner?
mock.fn() from node:test creates a spy/mock function that tracks calls, arguments, and return values. You can also use mock.method(object, 'methodName') to replace a method on an object and restore it afterwards with mock.restoreAll().
4 / 5
What does the --watch flag do when running Node.js tests?
The --watch flag (e.g., node --test --watch) tells the Node.js test runner to monitor the tested files for changes and automatically re-run affected tests. This gives a fast feedback loop without needing a separate file-watcher tool.
5 / 5
How are tests grouped in the Node.js built-in test runner?
describe() groups related tests in the Node.js test runner, functioning identically to Jest or Mocha. You can nest describe blocks for sub-groups, and each describe gets its own lifecycle hooks (before, after, beforeEach, afterEach).