-
-
Notifications
You must be signed in to change notification settings - Fork 929
/
validateObjectWithArrayProps.test.js
62 lines (53 loc) · 1.56 KB
/
validateObjectWithArrayProps.test.js
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
57
58
59
60
61
62
"use strict";
const validateObjectWithArrayProps = require("../validateObjectWithArrayProps");
describe("validateObjectWithArrayProps", () => {
it("should return a function", () => {
expect(validateObjectWithArrayProps(x => x)).toBeInstanceOf(Function);
});
describe("returned validator", () => {
const validator = validateObjectWithArrayProps(x => x);
it("should return false if any of the object properties are not an array", () => {
expect(
validator({
arrayProp: [1, 2],
nonArrayProp: 3
})
).toBeFalsy();
});
it("should return false if any of the object properties array values do not pass the test", () => {
expect(
validator({
arrayProp: [1, 2],
nonArrayProp: [0, 3]
})
).toBeFalsy();
});
it("should return true otherwise", () => {
expect(
validator({
arrayProp: [1, 2],
nonArrayProp: [3, 4]
})
).toBeTruthy();
});
});
describe("returned validator with array", () => {
const validator = validateObjectWithArrayProps([x => x > 0, x => x < 0]);
it("should accept an array of validators, any of which can return true", () => {
expect(
validator({
arrayProp: [1, 2],
nonArrayProp: [-1, 3]
})
).toBeTruthy();
});
it("should be false if none of the validators are true for any value", () => {
expect(
validator({
arrayProp: [1, 2],
nonArrayProp: [-1, 0]
})
).toBeFalsy();
});
});
});