21 lines
490 B
JavaScript
21 lines
490 B
JavaScript
import { test, expect } from "vitest";
|
|
|
|
import Ajv from "ajv";
|
|
|
|
import characterSchema from "../schemas-json/character.json";
|
|
|
|
const ajv = new Ajv();
|
|
const validate = ajv.compile(characterSchema.$defs.statistic);
|
|
|
|
test("good statistic", () => {
|
|
expect(validate(12)).toBeTruthy();
|
|
expect(validate.errors).toBeNull();
|
|
});
|
|
|
|
test("bad statistic", () => {
|
|
expect(validate(21)).toBeFalsy();
|
|
expect(validate.errors[0]).toMatchObject({
|
|
message: "must be <= 20",
|
|
});
|
|
});
|