-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathstring.test.ts
More file actions
56 lines (38 loc) · 1.71 KB
/
string.test.ts
File metadata and controls
56 lines (38 loc) · 1.71 KB
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
46
47
48
49
50
51
52
53
54
55
56
import { compileSchema } from "../compileSchema";
import { strict as assert } from "assert";
describe("keyword : string : validation", () => {
it("should return error for string shorter than minLength", () => {
const node = compileSchema({ type: "string", minLength: 2 });
const { errors } = node.validate("a");
assert.equal(errors.length, 1);
assert.deepEqual(errors[0].code, "min-length-error");
});
it("should NOT return error for string matching minLength", () => {
const node = compileSchema({ type: "string", minLength: 2 });
const { errors } = node.validate("ab");
assert.equal(errors.length, 0);
});
it("should return error for string larger than maxLength", () => {
const node = compileSchema({ type: "string", maxLength: 2 });
const { errors } = node.validate("abc");
assert.equal(errors.length, 1);
assert.deepEqual(errors[0].code, "max-length-error");
});
it("should NOT return error for string matching maxLength", () => {
const node = compileSchema({ type: "string", maxLength: 2 });
const { errors } = node.validate("ab");
assert.equal(errors.length, 0);
});
});
describe("keyword : string : default data", () => {
it("should return default value if string is undefined", () => {
const node = compileSchema({ type: "string", default: "abc" });
const data = node.getData();
assert.deepEqual(data, "abc");
});
it("should NOT return default value if string is undefined", () => {
const node = compileSchema({ type: "string", default: "abc" });
const data = node.getData("123");
assert.deepEqual(data, "123");
});
});