| name | write-tests |
| description | Write unit tests following this repo's conventions for backend (NestJS, ts-jest, *.spec.ts) and mobile (jest-expo, *.test.ts, RNFB/native mocking). Use when adding test coverage for services, guards, pipes, hooks, stores, or utilities. |
Writing tests
Backend (backend/, *.spec.ts under src/, ts-jest)
- Instantiate plain classes directly with mocked deps:
new Service(mockPrisma as never).
- Mock Prisma as a plain object; for
$transaction(async (tx) => ...) use
$transaction: jest.fn((cb) => cb(tx)) with a tx mock exposing the models used.
- For modules mocked via factory referencing outer vars, name them
mock*
(jest hoisting allows mock-prefixed names), e.g. const mockVerifyIdToken = jest.fn().
- Test guards by faking
ExecutionContext:
{ switchToHttp: () => ({ getRequest: () => ({ headers: {...} }) }) } as unknown as ExecutionContext.
- Manage
process.env with save/restore in beforeEach/afterAll for env-driven code.
- Run:
bun run test (config in package.json; testRegex = .spec.ts$).
Mobile (mobile/, *.test.ts(x), jest-expo)
Add a test for any non-trivial logic you add (services/guards/pipes/crypto on backend;
pure functions, stores, api/error helpers, push lifecycle on mobile).