Loading video player…

Welcome to Snowline Hire's Fitting Tests

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:

Language: Shell
python -m pytest -q

pytest passes all eleven:

Language: Program Output
...........                                      [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:

Language: Shell
node --test test_fitting.js

It prints this report:

Language: Program Output
✔ 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 --test finds, and compare values and objects with node:assert/strict
  • Check errors with assert.throws(), and run one test over many cases
  • Share setup with beforeEach(), and test async code with assert.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.

Download

Sample Code (.zip)

42.5 KB
Download

Course Slides (.pdf)

680.8 KB

Become a Member to join the conversation.