Documentation
    Preparing search index...
    • Configures jest-openapi to validate responses against an OpenAPI specification.

      This function bridges jest-openapi (which relies on a global expect) with Vitest's local expect instance, then resets the global to avoid polluting other tests.

      Parameters

      • path: string

        Absolute or relative path to the OpenAPI specification file (JSON or YAML)

      Returns void

      The recommended approach is to call this from a Vitest setup file so it runs once before the entire suite:

      // tests/setup.ts
      import { setupOpenapi } from '@map-colonies/vitest-utils';

      setupOpenapi('/path/to/openapi.yaml');
      // vitest.config.ts
      export default defineProject({
      test: {
      setupFiles: ['./tests/setup.ts'],
      },
      });

      Alternatively, call it inside a beforeAll when you need per-suite control:

      beforeAll(function () {
      setupOpenapi('/path/to/openapi.yaml');
      });

      it('should satisfy the OpenAPI spec', async function () {
      const response = await supertest(app).get('/resource');
      expect(response).toSatisfyApiSpec();
      });