Test, inspect, and ship

Test real queries in isolation

Run migrations and repository operations against a fresh temporary SQLite database so tests catch real schema and query mistakes.

8 minute lesson

~~~

A mocked Drizzle client can confirm a method call. It cannot prove the migration, SQL, constraints, and driver agree.

Create a temporary database for each test file or case, apply the real migrations, run the repository operation, and remove the file afterward. Keep tests independent so order never changes the result.

Test the failures the schema promises: duplicate email, missing author, ownership-bound update, and transaction rollback. A green insert test alone does not verify the important boundaries.

Using an in-memory database is fast, but a file-backed temporary database may better match configuration such as WAL mode and connection behavior. Choose deliberately and document the difference.

Write one integration test that migrates a fresh database, inserts a user and note, rejects an invalid author, and removes its file. Run two copies concurrently and prove they share no state.

Lesson completed

Take this course offline

Get every free book and course as PDF and EPUB files.

Get the download library →