JavaScript Testing for Pythonistas (Summary)

Snowline Hire’s fitting tests have made the move to JavaScript. You can now check the rules that put Morag on the right skis, load her booking from a file, and verify that a reservation holds both skis and boots. Kirsty’s Python tests gave you the requirements. Your JavaScript suite can check those same requirements before the booking site’s next change.

The project brought those checks together in fitting.test.js, and you completed the bookings and reservation tests in Finish the Test Suite. The useful result is a suite that passes for the supplied fitting module and catches mistakes in its replacements. Keep that distinction in mind when you add tests of your own.

Keep Each Check Specific

You can choose an assertion to match the requirement you’re checking. Imported from "node:assert/strict", assert.strictEqual() checks a single value and its type, while assert.deepStrictEqual() compares the contents of Morag’s fitting object. Python’s dict equality compares contents, but JavaScript’s === compares object identity. Passing the actual and expected objects to the assertion also gives you useful differences when a check fails.

Keep the strict import in new test files. Plain "node:assert" exposes the older, loose assert.equal(), which can let a number and a numeric string compare equal. The booking parser needs a test that catches that difference, because a height returned as text doesn’t meet the expected data contract.

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.