-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathisValid.test.ts
45 lines (40 loc) · 1.3 KB
/
isValid.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/* eslint quote-props: 0, no-unused-expressions: 0 */
import { expect } from "chai";
import isValid from "../../lib/isValid";
import { Draft04 as Core } from "../../lib/draft04";
describe("isValid", () => {
let draft: Core;
before(() => (draft = new Core()));
it("should return true if value is valid", () => {
const valid = isValid(draft, 4, { type: "number" });
expect(valid).to.be.true;
});
it("should return false if value is invalid", () => {
const valid = isValid(draft, 4, { type: "string" });
expect(valid).to.be.false;
});
// taken from spec: oneOf (complex)
// @fixme this is correct here, not when running tests through spec...
it("should not validate multiple oneOf validations", () => {
const valid = isValid(
draft,
{
foo: "baz",
bar: 2
},
{
oneOf: [
{
properties: { bar: { type: "integer" } },
required: ["bar"]
},
{
properties: { foo: { type: "string" } },
required: ["foo"]
}
]
}
);
expect(valid).to.be.false;
});
});