-
Notifications
You must be signed in to change notification settings - Fork 1
/
primitive-type.test.ts
104 lines (83 loc) · 2.02 KB
/
primitive-type.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import {
Null,
Type,
Undefined,
boolean,
func,
integer,
isArray,
number,
optional,
promise,
string,
} from '../src/type';
it('Test string', () => {
const Pet = new Type(string);
const pet = 'Kitty';
const errors = Pet.validate(pet);
expect(isArray(errors)).toBe(true);
expect(errors.length).toBe(0);
});
it('Test error string', () => {
const Pet = new Type(string);
const pet = 2;
const errors = Pet.validate(pet);
expect(isArray(errors)).toBe(true);
expect(errors.length).toBe(1); // one error
});
it('Test number', () => {
const Age = new Type(number);
const age = 23;
const errors = Age.validate(age);
expect(isArray(errors)).toBe(true);
expect(errors.length).toBe(0);
});
it('Test boolean', () => {
const A = new Type(boolean);
const a = false;
const errors = A.validate(a);
expect(isArray(errors)).toBe(true);
expect(errors.length).toBe(0);
});
it('Test integer', () => {
const A = new Type(integer);
const a = 123;
const errors = A.validate(a);
expect(isArray(errors)).toBe(true);
expect(errors.length).toBe(0);
});
it('Test Null', () => {
const A = new Type(Null);
const a = null;
const errors = A.validate(a);
expect(isArray(errors)).toBe(true);
expect(errors.length).toBe(0);
});
it('Test Undefined', () => {
const A = new Type(Undefined);
const a = undefined;
const errors = A.validate(a);
expect(isArray(errors)).toBe(true);
expect(errors.length).toBe(0);
});
it('Test func', () => {
const A = new Type(func);
const a = () => {};
const errors = A.validate(a);
expect(isArray(errors)).toBe(true);
expect(errors.length).toBe(0);
});
it('Test promise', () => {
const A = new Type(promise);
const a = new Promise((_resolve, _reject) => {});
const errors = A.validate(a);
expect(isArray(errors)).toBe(true);
expect(errors.length).toBe(0);
});
it('Test optional', () => {
const A = new Type(optional);
const a = undefined;
expect(A.validate(a).length).toBe(0);
const b = 123;
expect(A.validate(b).length).toBe(0);
});