Untitled Lesson
Skill Matrix
UNLOCK NODES BY LEARNING NEW TAGS.
You want to spy on a function call and assert it was called exactly once, without adding Sinon.js as a dependency. Which built-in `node:test` feature covers this?
š» Code Challenge | +75 XP
Write a node:test suite for a pure `calculateDiscount(price, percent)` function covering a normal case, a zero-percent edge case, and a negative-price error case, using describe/test and node:assert.
A new hire tries to run `npm test` on a service using node:test and gets "command not found" because no test script exists yet. Reorder the steps to fix the setup.
Task: Reorder the blocks in logical sequence to solve the problem.
A.D.A. Interface
Adaptive Didactic Assistant

Pascual Vila
Frontend Instructor // Code Syllabus
The Error //
Naming test files without the recognized convention (e.g. userSpec.js instead of user.test.js)
// Wrong: silently skipped by default discovery
// file: userSpec.js
// Correct: matches default node:test discovery
// file: user.test.jsThe Solution //
node --test only auto-discovers files matching its default patterns (e.g. *.test.js, files under a test/ directory). A file named outside that convention is silently skipped ā the run reports zero failures because it never found any tests to fail, giving a false sense of a passing suite.
The Error //
Expecting Jest-style matchers like toMatchObject or toHaveBeenCalledWith to exist in node:assert
// Wrong: not a real node:assert method
// assert.toMatchObject(result, { id: 1 });
// Correct
assert.deepStrictEqual(result, { id: 1, name: "Ada", active: true });The Solution //
node:assert is intentionally minimal compared to Jest's expect() API ā it has no toMatchObject-style partial matching. For structural comparisons, use assert.deepStrictEqual with a fully-specified expected object, or accept that some Jest idioms require slightly more verbose assertions in the native runner.