Testing During Development
How to locally test the app during development.
Local Unit Tests
Before submitting your updates, verify they pass all unit tests. Follow these steps to run tests locally:
-
Copy your
.env.examplefile in the/apifolder and rename it to.envcp .env.example ./api/.env -
Add
NODE_ENV=CIto your/api/.envfile -
npm run test:client -
npm run test:api -
npm run test:packages:api -
npm run test:packages:data-provider -
npm run test:packages:data-schemas
Running Tests Per-Workspace
Tests are run using Jest from their respective workspace directories. Target specific test files with patterns:
cd api && npx jest <pattern>
cd packages/api && npx jest <pattern>
cd packages/data-provider && npx jest <pattern>
cd packages/data-schemas && npx jest <pattern>
cd client && npx jest <pattern>Testing Philosophy
- Prefer real logic over mocks. Mock only what cannot be controlled locally, such as external HTTP APIs, rate-limited services, and non-deterministic system calls.
- Use spies when you need to assert that real functions were called with expected arguments.
- Use
mongodb-memory-serverfor MongoDB-backed tests so queries and schema validation run against real database behavior. - Cover loading, success, and error states for UI/data flows.
Tip
Use test/layout-test-utils for rendering components in frontend tests.
How is this guide?