UNPKG

easy-schema-validator

Version:
65 lines 2.32 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const index_1 = require("./index"); it("validates empty schema and data", () => __awaiter(void 0, void 0, void 0, function* () { const schema = {}; const data = {}; const validator = new index_1.default(schema); const errors = yield validator.validate(data); expect(errors).toHaveLength(0); })); it("errors with invalid data", () => __awaiter(void 0, void 0, void 0, function* () { const schema = { type: "object", additionalProperties: false, properties: {}, }; const data = { additional: "property", }; const validator = new index_1.default(schema); const errors = yield validator.validate(data); expect(errors).toHaveLength(1); })); it("collects defaults", () => __awaiter(void 0, void 0, void 0, function* () { const schema = { type: "object", additionalProperties: false, required: ["name", "age", "pets"], properties: { name: { type: "string" }, age: { type: "number", }, pets: { type: "array", items: { type: "string" }, default: [], }, }, }; const data = { name: "Sue", age: 32, }; const validator = new index_1.default(schema); const errors = yield validator.validate(data); expect(errors).toHaveLength(0); expect(data).toEqual({ name: "Sue", age: 32, pets: [], }); })); //# sourceMappingURL=index.spec.js.map