Previously: In Creating Your First Postgres Database Module, you created and deployed the pets module. Now let's add tests.
Testing database logic requires real Postgres—not mocks. Your pgpm workspace comes with testing configured, so you can start writing tests immediately.
Prerequisites
Requires: Complete Creating Your First Postgres Database Module.
Step 1: Install Dependencies
Navigate to your workspace root and install dependencies:
This installs the testing dependencies configured by pgpm init workspace.
Note: If you haven't already, make sure to bootstrap database users (covered in Prerequisites). This creates
anonymous,authenticated, andadministratorroles for realistic testing scenarios. Run this once:
Step 2: Write Your First Test
Navigate to your pets module and create/update __tests__/basic.test.ts:
Step 3: Run Tests
Start Jest:
You'll see:
What's Next
You've added tests to your module. In the next lesson, we'll explore module dependencies—creating modules that depend on other modules and using cross-module references.
Key Takeaways
- pgpm workspaces come with testing configured out of the box
- Run
pnpm testto verify your database module - Tests automatically deploy your module with zero configuration
- Each test starts with a clean state—no manual cleanup needed
