This course shows you how to test JavaScript with the runner and assertions built into Node.
Your project is to port the pytest suite Kirsty wrote for a ski-hire shop’s fitting module. The
module’s already in JavaScript; its tests aren’t. Here’s a first taste. Kirsty’s Python suite,
test_fitting.py, has eleven tests. Run it with pytest:
python -m pytest -q
pytest passes all eleven:
........... [100%]
11 passed in 0.04s
Port the suite to JavaScript as functions, as in Python, so that def test_out_of_stock():
becomes function test_out_of_stock() {, and hand the file, test_fitting.js, to Node’s
runner:
node --test test_fitting.js
It prints this report:
✔ test_fitting.js (58.645595ms)
ℹ tests 1
ℹ suites 0
ℹ pass 1
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 68.803693
exit code 0
It counts one test, not eleven, and names it after the file. It passed, and the run exits with code zero.
pytest does a lot for you, from diffs on failing asserts to parametrized tests. Node’s runner does some of it differently. A run can succeed without checking anything. That’s where this course starts.
Snowline Hire rents skis and boots. Its fitting module picks each customer’s skis and holds them in stock. Its booking site is moving to JavaScript, tests and all.
By the end of this course, you’ll be able to:
- Write test files that
node --testfinds, and compare values and objects withnode:assert/strict - Check errors with
assert.throws(), and run one test over many cases - Share setup with
beforeEach(), and test async code withassert.rejects() - Replace a collaborator with
t.mock - Port Snowline Hire’s whole pytest suite to JavaScript
You only need to know how to write pytest suites with plain assert, pytest.raises(),
parametrize, fixtures, an async test and monkeypatch. In JavaScript, you only need to know how
to write modules with import and export, classes, your own error classes, and async functions
with await.
The examples use Node 26, and Python 3.15 with pytest and pytest-asyncio.
The course mixes short videos and text lessons, with exercises where you write the tests yourself. Every video has a summary below it, and a quiz and a summary close the course.
Next up: Running Your First Test With node –test, a video that starts from Kirsty’s first test.