Skip to main content

Testing

The project uses Vitest as the testing framework.

Conventions

  • No describe blocks, just plain it() calls
  • it messages start with should
  • Use parseResponse() instead of res.json()
  • Use sanitizeForSnapshot() for snapshot tests
  • Mock config with vi.mock and mockConfig
  • Fixtures come from packages, never inline

Example

import { it, expect } from 'vitest';
import { setupApp } from './setupApp';
import { parseResponse } from '@nittio/utils';

it('should return event by id', async () => {
const { app } = setupApp();

const res = await app.request('/event/123');
const body = await parseResponse(res);

expect(body.success).toBe(true);
expect(body.data).toBeDefined();
});

Setup

API tests use the setupApp() pattern with createTestApp():

const setupApp = () => {
const app = createTestApp();
// register routes
return { app };
};

Running

yarn test              # all tests
yarn test:watch # watch mode
yarn test:ui # visual interface
yarn test:coverage # with coverage