Replacing Fixtures With Hooks
Pytest requests a fixture by parameter name. A node:test callback receives a test context instead, whatever its parameter is called. The conventional name is t; it doesn’t request test data.
Use beforeEach() to build a fresh Morag booking before each test in this file. A surrounding let binding lets the setup callback replace the object and the test callbacks read it. This gives each fitting check independent starting data:
fitting.test.js
import assert from "node:assert/strict";
import { beforeEach, test } from "node:test";
import { fit } from "./fitting.js";
let morag;
beforeEach(() => {
morag = {
name: "Morag Fraser", height: 168, weight: 62,
boot: 6, ability: "intermediate",
};
});
test("afternoon booking", () => {
morag.ability = "expert";
assert.strictEqual(fit(morag).skis, 160);
});
test("fit", () => {
assert.deepStrictEqual(fit(morag), {
name: "Morag Fraser", skis: 155,
boots: 24.5, din: 5,
});
});
Run the file from your existing ski-fitting folder with this command. The reporter option selects the readable report used in the video: