Testing Node.js · Lecture 3

One real database

One query, one coupon row, one assertion.

getCoupon runs a SELECT against SQLite. The test creates one table, inserts one coupon row, and makes one assertion: ten percent off 100 is 90. The response is still the fake from lecture 2. A missing file, a missing table, a missing row, or a bad date can fail the test before that assertion. That is why this test comes after the unit tests, not instead of them.

node --test lectures/03-database/database.test.js

Code: lectures/03-database. Node 24. No packages.