json-schema-library
Version:
Customizable and hackable json-validator and json-schema utilities for traversal, data generation and validation
23 lines (19 loc) • 833 B
text/typescript
import { compileSchema } from "../compileSchema";
import { strict as assert } from "assert";
describe("keyword : type : validation", () => {
describe("integer", () => {
it("should support type 'integer'", () => {
const { errors } = compileSchema({ type: "integer" }).validate(1);
assert.equal(errors.length, 0);
});
it("should throw error if type 'integer' received a float", () => {
const { errors } = compileSchema({ type: "integer" }).validate(1.1);
assert.equal(errors.length, 1);
assert.equal(errors[0].code, "type-error");
});
it("should validate NaN", () => {
const { errors } = compileSchema({ type: "integer" }).validate(parseInt("a"));
assert.equal(errors.length, 0);
});
});
});