Testing
The project uses Vitest as the testing framework.
Conventions
- No
describeblocks, just plainit()calls itmessages start withshould- Use
parseResponse()instead ofres.json() - Use
sanitizeForSnapshot()for snapshot tests - Mock config with
vi.mockandmockConfig - 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