-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
26 lines (22 loc) · 1.05 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { expect } from 'vitest';
import type { OpenAPISpecObject } from 'openapi-validator';
import openapiValidator from 'openapi-validator';
import jestToSatisfyApiSpec from 'jest-openapi/dist/matchers/toSatisfyApiSpec.js';
import jestToSatisfySchemaInApiSpec from 'jest-openapi/dist/matchers/toSatisfySchemaInApiSpec.js';
interface CustomMatchers<R = unknown> {
toSatisfyApiSpec(): R;
toSatisfySchemaInApiSpec(schemaName: string): R;
}
declare module 'vitest' {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
interface Assertion<T = any> extends CustomMatchers<T> {}
interface AsymmetricMatchersContaining extends CustomMatchers {}
}
export default (filepathOrObject: string | OpenAPISpecObject): void => {
const openApiSpec = openapiValidator.makeApiSpec(filepathOrObject);
expect.extend({
toSatisfyApiSpec: (received: unknown) => jestToSatisfyApiSpec.default(received, openApiSpec),
toSatisfySchemaInApiSpec: (received: unknown, schemaName: string) =>
jestToSatisfySchemaInApiSpec.default(received, schemaName, openApiSpec)
});
};