UNPKG

json-schema-library

Version:

Customizable and hackable json-validator and json-schema utilities for traversal, data generation and validation

39 lines (32 loc) 1.39 kB
import { strict as assert } from "assert"; import { createSchema } from "./createSchema"; import { getTypeOf } from "../utils/getTypeOf"; describe("createSchema", () => { it("should add type 'object' of data to schema", () => { const res = createSchema({}); assert.deepEqual(res.type, "object"); }); it("should add type 'string' of data to schema", () => { const res = createSchema(""); assert.deepEqual(res, { type: "string" }); }); it("should should add object's properties", () => { const res = createSchema({ first: "", second: {} }); assert.deepEqual(Object.keys(res.properties), ["first", "second"]); }); it("should add items from array", () => { const res = createSchema(["string", false]); assert.deepEqual(res.items.length, 2); assert.deepEqual(res.items[0].type, "string"); assert.deepEqual(res.items[1].type, "boolean"); }); it("should add single item as item-object", () => { const res = createSchema(["string"]); assert.deepEqual(getTypeOf(res.items), "object"); assert.deepEqual(res.items, { type: "string" }); }); it("should create item-object if array items are of same type", () => { const res = createSchema(["string", "another string"]); assert.deepEqual(res.items, { type: "string" }); }); });