@playwright-labs/fixture-ajv-ts
v1.0.1
Published
Utility to test your schema for ajv-ts package
Maintainers
Readme
Ajv-ts fixture
Get started
- Install the package(s)
pnpm i @playwright/test
pnpm i ajv-ts
pnpm i @playwright-labs/fixture-ajv-ts- Add (or create) in your fixture
// file: fixture.ts
import { mergeExpects, mergeTests } from "@playwright/test";
import {
expect as ajvTsExpect,
test as ajvTsTests,
} from "@playwright-labs/fixture-ajv-ts";
export const expect = mergeExpects(ajvTsExpect);
export const test = mergeTests(ajvTsTests);- Use it!
import { test, expect } from "./fixture";
test("use some schema", async ({ schema }) => {
const mySchema = schema.string();
expect("qwe").toMatchSchema(mySchema); // OK
});- Or define schema separately and use it for test:
// api-response.ts
import { s } from "ajv-ts";
export const someResponse = s.object({
data: s.string().or(s.number()),
});import { someResponse } from "./api-response";
import { test, expect } from "./fixture";
test("use some schema", async () => {
const resp = await fetch("https://example.com/data.json");
expect(await resp.json()).toMatchSchema(someResponse);
});