@cleverbrush/schema 0.0.17 → 1.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +213 -163
- package/package.json +3 -3
- package/src/builders/ArraySchemaBuilder.test.ts +270 -0
- package/src/builders/ArraySchemaBuilder.ts +381 -0
- package/src/builders/BooleanSchemaBuilder.test.ts +196 -0
- package/src/builders/BooleanSchemaBuilder.ts +155 -0
- package/src/builders/FunctionSchemaBuilder.test.ts +134 -0
- package/src/builders/FunctionSchemaBuilder.ts +109 -0
- package/src/builders/NumberSchemaBuilder.test.ts +493 -0
- package/src/builders/NumberSchemaBuilder.ts +789 -0
- package/src/builders/ObjectSchemaBuilder.test.ts +657 -0
- package/src/builders/ObjectSchemaBuilder.ts +794 -0
- package/src/builders/SchemaBuilder.test.ts +73 -0
- package/src/builders/SchemaBuilder.ts +135 -0
- package/src/builders/StringSchemaBuilder.test.ts +318 -0
- package/src/builders/StringSchemaBuilder.ts +392 -0
- package/src/builders/UnionSchemaBuilder.test.ts +162 -0
- package/src/builders/UnionSchemaBuilder.ts +154 -0
- package/src/defaultSchemas.ts +44 -0
- package/src/index.ts +58 -190
- package/src/schema.ts +827 -0
- package/src/schemaRegistry.builders.test.ts +1393 -0
- package/src/schemaRegistry.test.ts +118 -0
- package/src/schemaRegistry.ts +461 -0
- package/src/validators/validateArray.ts +4 -7
- package/src/validators/validateBoolean.ts +2 -11
- package/src/validators/validateFunction.ts +25 -0
- package/src/validators/validateNumber.ts +2 -7
- package/src/validators/validateObject.ts +32 -21
- package/src/validators/validateString.ts +2 -7
- package/src/validators/validateUnion.ts +36 -0
- package/dist/index.d.ts +0 -94
- package/dist/index.js +0 -9
- package/dist/schemaValidator.d.ts +0 -16
- package/dist/schemaValidator.js +0 -234
- package/dist/validators/validateArray.d.ts +0 -2
- package/dist/validators/validateArray.js +0 -60
- package/dist/validators/validateBoolean.d.ts +0 -2
- package/dist/validators/validateBoolean.js +0 -33
- package/dist/validators/validateNumber.d.ts +0 -2
- package/dist/validators/validateNumber.js +0 -69
- package/dist/validators/validateObject.d.ts +0 -2
- package/dist/validators/validateObject.js +0 -73
- package/dist/validators/validateString.d.ts +0 -2
- package/dist/validators/validateString.js +0 -50
- package/src/schemaValidator.test.ts +0 -1656
- package/src/schemaValidator.ts +0 -367
|
@@ -0,0 +1,493 @@
|
|
|
1
|
+
import { deepEqual } from '@cleverbrush/deep';
|
|
2
|
+
|
|
3
|
+
import { Schema } from '../schema.js';
|
|
4
|
+
import { number } from './NumberSchemaBuilder.js';
|
|
5
|
+
|
|
6
|
+
test('Clean', () => {
|
|
7
|
+
const schema = number();
|
|
8
|
+
expect(schema).toHaveProperty('type', 'number');
|
|
9
|
+
expect(schema).toHaveProperty('isRequired', true);
|
|
10
|
+
expect(schema).toHaveProperty('isNullable', false);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test('optional', () => {
|
|
14
|
+
const schema = number().optional();
|
|
15
|
+
expect(schema).toHaveProperty('type', 'number');
|
|
16
|
+
expect(schema).toHaveProperty('isRequired', false);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('optional - 2', () => {
|
|
20
|
+
const schema = number().optional().required();
|
|
21
|
+
expect(schema).toHaveProperty('type', 'number');
|
|
22
|
+
expect(schema).toHaveProperty('isRequired', true);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('optional - 3', () => {
|
|
26
|
+
const schema1 = number();
|
|
27
|
+
const schema2 = schema1.optional();
|
|
28
|
+
const e = (schema1 as Schema) === (schema2 as Schema);
|
|
29
|
+
const isRequiredEqual = (schema1 as any).isRequired !== schema2.isRequired;
|
|
30
|
+
expect(e).toEqual(false);
|
|
31
|
+
expect(isRequiredEqual).toEqual(true);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('optional - 4', () => {
|
|
35
|
+
const schema1 = number().optional();
|
|
36
|
+
const schema2 = schema1.optional();
|
|
37
|
+
const e = (schema1 as Schema) === (schema2 as Schema);
|
|
38
|
+
const isRequiredEqual = (schema1 as any).isRequired === schema2.isRequired;
|
|
39
|
+
expect(e).toEqual(true);
|
|
40
|
+
expect(isRequiredEqual).toEqual(true);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('optional - 5', () => {
|
|
44
|
+
const schema1 = number();
|
|
45
|
+
const schema2 = schema1.required();
|
|
46
|
+
const e = (schema1 as Schema) === (schema2 as Schema);
|
|
47
|
+
const isRequiredEqual = (schema1 as any).isRequired === schema2.isRequired;
|
|
48
|
+
expect(e).toEqual(true);
|
|
49
|
+
expect(isRequiredEqual).toEqual(true);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('optional - 6', () => {
|
|
53
|
+
const schema1 = number().optional();
|
|
54
|
+
const schema2 = schema1.required();
|
|
55
|
+
const e = (schema1 as Schema) === (schema2 as Schema);
|
|
56
|
+
const isRequiredEqual = (schema1 as any).isRequired === schema2.isRequired;
|
|
57
|
+
expect(e).toEqual(false);
|
|
58
|
+
expect(isRequiredEqual).toEqual(false);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('optional - 7', () => {
|
|
62
|
+
const schema1 = number().optional().required();
|
|
63
|
+
const schema2 = schema1.required();
|
|
64
|
+
const e = (schema1 as Schema) === (schema2 as Schema);
|
|
65
|
+
const isRequiredEqual = (schema1 as any).isRequired === schema2.isRequired;
|
|
66
|
+
expect(e).toEqual(true);
|
|
67
|
+
expect(isRequiredEqual).toEqual(true);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('nullable - 1', () => {
|
|
71
|
+
const schema = number().nullable();
|
|
72
|
+
expect(schema).toHaveProperty('type', 'number');
|
|
73
|
+
expect(schema).toHaveProperty('isNullable', true);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test('nullable - 2', () => {
|
|
77
|
+
const schema = number().nullable().notNullable();
|
|
78
|
+
expect(schema).toHaveProperty('type', 'number');
|
|
79
|
+
expect(schema).toHaveProperty('isNullable', false);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test('nullable - 3', () => {
|
|
83
|
+
const schema1 = number();
|
|
84
|
+
const schema2 = schema1.nullable();
|
|
85
|
+
const e = (schema1 as Schema) === (schema2 as Schema);
|
|
86
|
+
const isNullableEqual = (schema1 as any).isNullable !== schema2.isNullable;
|
|
87
|
+
expect(e).toEqual(false);
|
|
88
|
+
expect(isNullableEqual).toEqual(true);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test('nullable - 4', () => {
|
|
92
|
+
const schema1 = number().nullable();
|
|
93
|
+
const schema2 = schema1.nullable();
|
|
94
|
+
const e = (schema1 as Schema) === (schema2 as Schema);
|
|
95
|
+
const isNullableEqual = (schema1 as any).isNullable === schema2.isNullable;
|
|
96
|
+
expect(e).toEqual(true);
|
|
97
|
+
expect(isNullableEqual).toEqual(true);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test('nullable - 5', () => {
|
|
101
|
+
const schema1 = number();
|
|
102
|
+
const schema2 = schema1.nullable();
|
|
103
|
+
const e = (schema1 as Schema) === (schema2 as Schema);
|
|
104
|
+
const isNullableEqual = (schema1 as any).isNullable === schema2.isNullable;
|
|
105
|
+
expect(e).toEqual(false);
|
|
106
|
+
expect(isNullableEqual).toEqual(false);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test('nullable - 6', () => {
|
|
110
|
+
const schema1 = number();
|
|
111
|
+
const schema2 = schema1.notNullable();
|
|
112
|
+
const e = (schema1 as Schema) === (schema2 as Schema);
|
|
113
|
+
const isNullableEqual = (schema1 as any).isNullable === schema2.isNullable;
|
|
114
|
+
expect(e).toEqual(true);
|
|
115
|
+
expect(isNullableEqual).toEqual(true);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test('nullable - 7', () => {
|
|
119
|
+
const schema1 = number().nullable();
|
|
120
|
+
const schema2 = schema1.notNullable();
|
|
121
|
+
const e = (schema1 as Schema) === (schema2 as Schema);
|
|
122
|
+
const isNullableEqual = (schema1 as any).isNullable === schema2.isNullable;
|
|
123
|
+
expect(e).toEqual(false);
|
|
124
|
+
expect(isNullableEqual).toEqual(false);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test('equals - 1', () => {
|
|
128
|
+
const schema = number().equals(10);
|
|
129
|
+
expect(schema._schema).toHaveProperty('type', 'number');
|
|
130
|
+
expect(schema._schema).toHaveProperty('equals', 10);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test('equals - 2', () => {
|
|
134
|
+
const schema = number();
|
|
135
|
+
expect(schema._schema).toHaveProperty('type', 'number');
|
|
136
|
+
expect(schema._schema).not.toHaveProperty('equals');
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test('equals - 4', () => {
|
|
140
|
+
const schema = number().equals(10).clearEquals();
|
|
141
|
+
expect(schema._schema).toHaveProperty('type', 'number');
|
|
142
|
+
expect(schema._schema).not.toHaveProperty('equals');
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test('equals - 5', () => {
|
|
146
|
+
const schema1 = number();
|
|
147
|
+
const schema2 = schema1.equals(20);
|
|
148
|
+
const equals = schema1._schema.equals === schema2._schema.equals;
|
|
149
|
+
expect(equals).toEqual(false);
|
|
150
|
+
expect(schema1._schema).not.toHaveProperty('equals');
|
|
151
|
+
expect(schema2._schema).toHaveProperty('equals', 20);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test('equals - 6', () => {
|
|
155
|
+
const schema1 = number().equals(20);
|
|
156
|
+
const schema2 = schema1.equals(20);
|
|
157
|
+
const equals = schema1._schema.equals === schema2._schema.equals;
|
|
158
|
+
expect(equals).toEqual(true);
|
|
159
|
+
expect(schema1._schema).toHaveProperty('equals', 20);
|
|
160
|
+
expect(schema2._schema).toHaveProperty('equals', 20);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
test('equals - 6', () => {
|
|
164
|
+
const schema1 = number().equals(20);
|
|
165
|
+
const schema2 = schema1.clearEquals();
|
|
166
|
+
const equals = schema1._schema.equals === schema2._schema.equals;
|
|
167
|
+
expect(equals).toEqual(false);
|
|
168
|
+
expect(schema1._schema).toHaveProperty('equals', 20);
|
|
169
|
+
expect(schema2._schema).not.toHaveProperty('equals');
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
test('equals - 7', () => {
|
|
173
|
+
const schema1 = number().equals(20).clearEquals();
|
|
174
|
+
const schema2 = schema1.clearEquals();
|
|
175
|
+
const equals = (schema1 as any) === schema2;
|
|
176
|
+
expect(equals).toEqual(true);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
test('min - 1', () => {
|
|
180
|
+
const schema = number();
|
|
181
|
+
expect(schema._schema).not.toHaveProperty('min');
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
test('min - 2', () => {
|
|
185
|
+
const schema = number().min(20);
|
|
186
|
+
expect(schema._schema).toHaveProperty('min', 20);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
test('min - 3', () => {
|
|
190
|
+
const schema = number().min(20).clearMin();
|
|
191
|
+
expect(schema._schema).not.toHaveProperty('min');
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
test('min - 4', () => {
|
|
195
|
+
const schema1 = number();
|
|
196
|
+
const schema2 = schema1.min(20);
|
|
197
|
+
const equal = (schema1 as any) === schema2;
|
|
198
|
+
expect(equal).toEqual(false);
|
|
199
|
+
expect(schema1._schema).not.toHaveProperty('min');
|
|
200
|
+
expect(schema2._schema).toHaveProperty('min', 20);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
test('min - 5', () => {
|
|
204
|
+
const schema1 = number().min(20);
|
|
205
|
+
const schema2 = schema1.min(20);
|
|
206
|
+
const equal = (schema1 as any) === schema2;
|
|
207
|
+
expect(equal).toEqual(true);
|
|
208
|
+
expect(schema1._schema).toHaveProperty('min', 20);
|
|
209
|
+
expect(schema2._schema).toHaveProperty('min', 20);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
test('min - 6', () => {
|
|
213
|
+
const schema1 = number().min(20);
|
|
214
|
+
const schema2 = schema1.clearMin();
|
|
215
|
+
const equal = (schema1 as any) === schema2;
|
|
216
|
+
expect(equal).toEqual(false);
|
|
217
|
+
expect(schema1._schema).toHaveProperty('min', 20);
|
|
218
|
+
expect(schema2._schema).not.toHaveProperty('min');
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
test('min - 7', () => {
|
|
222
|
+
const schema1 = number();
|
|
223
|
+
const schema2 = schema1.clearMin();
|
|
224
|
+
const equal = (schema1 as any) === schema2;
|
|
225
|
+
expect(equal).toEqual(true);
|
|
226
|
+
expect(schema1._schema).not.toHaveProperty('min');
|
|
227
|
+
expect(schema2._schema).not.toHaveProperty('min');
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
test('min - 8', () => {
|
|
231
|
+
const schema1 = number().clearMin();
|
|
232
|
+
const schema2 = schema1.clearMin();
|
|
233
|
+
const equal = (schema1 as any) === schema2;
|
|
234
|
+
expect(equal).toEqual(true);
|
|
235
|
+
expect(schema1._schema).not.toHaveProperty('min');
|
|
236
|
+
expect(schema2._schema).not.toHaveProperty('min');
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
test('max - 1', () => {
|
|
240
|
+
const schema = number();
|
|
241
|
+
expect(schema._schema).not.toHaveProperty('max');
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
test('max - 2', () => {
|
|
245
|
+
const schema = number().max(30);
|
|
246
|
+
expect(schema._schema).toHaveProperty('max', 30);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
test('max - 3', () => {
|
|
250
|
+
const schema = number().max(30).clearMax();
|
|
251
|
+
expect(schema._schema).not.toHaveProperty('max');
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
test('max - 4', () => {
|
|
255
|
+
const schema1 = number();
|
|
256
|
+
const schema2 = schema1.max(20);
|
|
257
|
+
const equal = (schema1 as any) === schema2;
|
|
258
|
+
expect(equal).toEqual(false);
|
|
259
|
+
expect(schema1._schema).not.toHaveProperty('max');
|
|
260
|
+
expect(schema2._schema).toHaveProperty('max', 20);
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
test('max - 5', () => {
|
|
264
|
+
const schema1 = number().max(20);
|
|
265
|
+
const schema2 = schema1.max(20);
|
|
266
|
+
const equal = (schema1 as any) === schema2;
|
|
267
|
+
expect(equal).toEqual(true);
|
|
268
|
+
expect(schema1._schema).toHaveProperty('max', 20);
|
|
269
|
+
expect(schema2._schema).toHaveProperty('max', 20);
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
test('max - 6', () => {
|
|
273
|
+
const schema1 = number().max(20);
|
|
274
|
+
const schema2 = schema1.clearMax();
|
|
275
|
+
const equal = (schema1 as any) === schema2;
|
|
276
|
+
expect(equal).toEqual(false);
|
|
277
|
+
expect(schema1._schema).toHaveProperty('max', 20);
|
|
278
|
+
expect(schema2._schema).not.toHaveProperty('max');
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
test('max - 7', () => {
|
|
282
|
+
const schema1 = number();
|
|
283
|
+
const schema2 = schema1.clearMax();
|
|
284
|
+
const equal = (schema1 as any) === schema2;
|
|
285
|
+
expect(equal).toEqual(true);
|
|
286
|
+
expect(schema1._schema).not.toHaveProperty('max');
|
|
287
|
+
expect(schema2._schema).not.toHaveProperty('max');
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
test('max - 8', () => {
|
|
291
|
+
const schema1 = number().clearMax();
|
|
292
|
+
const schema2 = schema1.clearMax();
|
|
293
|
+
const equal = (schema1 as any) === schema2;
|
|
294
|
+
expect(equal).toEqual(true);
|
|
295
|
+
expect(schema1._schema).not.toHaveProperty('max');
|
|
296
|
+
expect(schema2._schema).not.toHaveProperty('max');
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
test('min,max - 1', () => {
|
|
300
|
+
const schema = number().min(20).max(30);
|
|
301
|
+
expect(schema._schema).toHaveProperty('min', 20);
|
|
302
|
+
expect(schema._schema).toHaveProperty('max', 30);
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
test('isInteger - 1', () => {
|
|
306
|
+
const schema = number();
|
|
307
|
+
expect(schema._schema).not.toHaveProperty('isInteger');
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
test('isInteger - 2', () => {
|
|
311
|
+
const schema = number().isInteger();
|
|
312
|
+
expect(schema._schema).toHaveProperty('isInteger', true);
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
test('isInteger - 3', () => {
|
|
316
|
+
const schema = number().isInteger().canBeNotInteger();
|
|
317
|
+
expect(schema._schema).not.toHaveProperty('isInteger');
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
test('isInteger - 4', () => {
|
|
321
|
+
const schema1 = number();
|
|
322
|
+
const schema2 = schema1.isInteger();
|
|
323
|
+
const equal = (schema1 as any) === schema2;
|
|
324
|
+
expect(equal).toEqual(false);
|
|
325
|
+
expect(schema1._schema).not.toHaveProperty('isInteger');
|
|
326
|
+
expect(schema2._schema).toHaveProperty('isInteger', true);
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
test('isInteger - 5', () => {
|
|
330
|
+
const schema1 = number().isInteger();
|
|
331
|
+
const schema2 = schema1.isInteger();
|
|
332
|
+
const equal = (schema1 as any) === schema2;
|
|
333
|
+
expect(equal).toEqual(true);
|
|
334
|
+
expect(schema1._schema).toHaveProperty('isInteger', true);
|
|
335
|
+
expect(schema2._schema).toHaveProperty('isInteger', true);
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
test('isInteger - 6', () => {
|
|
339
|
+
const schema1 = number();
|
|
340
|
+
const schema2 = schema1.canBeNotInteger();
|
|
341
|
+
const equal = (schema1 as any) === schema2;
|
|
342
|
+
expect(equal).toEqual(true);
|
|
343
|
+
expect(schema1._schema).not.toHaveProperty('isInteger');
|
|
344
|
+
expect(schema2._schema).not.toHaveProperty('isInteger');
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
test('isInteger - 7', () => {
|
|
348
|
+
const schema1 = number().canBeNotInteger();
|
|
349
|
+
const schema2 = schema1.canBeNotInteger();
|
|
350
|
+
const equal = (schema1 as any) === schema2;
|
|
351
|
+
expect(equal).toEqual(true);
|
|
352
|
+
expect(schema1._schema).not.toHaveProperty('isInteger');
|
|
353
|
+
expect(schema2._schema).not.toHaveProperty('isInteger');
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
test('NaN - 1', () => {
|
|
357
|
+
const schema = number();
|
|
358
|
+
expect(schema._schema).toHaveProperty('ensureNotNaN', true);
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
test('NaN - 2', () => {
|
|
362
|
+
const schema = number().notNaN();
|
|
363
|
+
expect(schema._schema).toHaveProperty('ensureNotNaN', true);
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
test('NaN - 3', () => {
|
|
367
|
+
const schema = number().canBeNaN();
|
|
368
|
+
expect(schema._schema).toHaveProperty('ensureNotNaN', false);
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
test('NaN - 4', () => {
|
|
372
|
+
const schema1 = number();
|
|
373
|
+
const schema2 = schema1.notNaN();
|
|
374
|
+
const equal = (schema1 as any) === schema2;
|
|
375
|
+
expect(equal).toEqual(true);
|
|
376
|
+
expect(schema1._schema).toHaveProperty('ensureNotNaN', true);
|
|
377
|
+
expect(schema2._schema).toHaveProperty('ensureNotNaN', true);
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
test('NaN - 5', () => {
|
|
381
|
+
const schema1 = number().notNaN();
|
|
382
|
+
const schema2 = schema1.notNaN();
|
|
383
|
+
const equal = (schema1 as any) === schema2;
|
|
384
|
+
expect(equal).toEqual(true);
|
|
385
|
+
expect(schema1._schema).toHaveProperty('ensureNotNaN', true);
|
|
386
|
+
expect(schema2._schema).toHaveProperty('ensureNotNaN', true);
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
test('NaN - 6', () => {
|
|
390
|
+
const schema1 = number();
|
|
391
|
+
const schema2 = schema1.canBeNaN();
|
|
392
|
+
const equal = (schema1 as any) === schema2;
|
|
393
|
+
expect(equal).toEqual(false);
|
|
394
|
+
expect(schema1._schema).toHaveProperty('ensureNotNaN', true);
|
|
395
|
+
expect(schema2._schema).toHaveProperty('ensureNotNaN', false);
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
test('NaN - 7', () => {
|
|
399
|
+
const schema1 = number().canBeNaN();
|
|
400
|
+
const schema2 = schema1.canBeNaN();
|
|
401
|
+
const equal = (schema1 as any) === schema2;
|
|
402
|
+
expect(equal).toEqual(true);
|
|
403
|
+
expect(schema1._schema).toHaveProperty('ensureNotNaN', false);
|
|
404
|
+
expect(schema2._schema).toHaveProperty('ensureNotNaN', false);
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
test('NaN - 8', () => {
|
|
408
|
+
const schema1 = number().canBeNaN();
|
|
409
|
+
const schema2 = schema1.notNaN();
|
|
410
|
+
const equal = (schema1 as any) === schema2;
|
|
411
|
+
expect(equal).toEqual(false);
|
|
412
|
+
expect(schema1._schema).toHaveProperty('ensureNotNaN', false);
|
|
413
|
+
expect(schema2._schema).toHaveProperty('ensureNotNaN', true);
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
test('Finite - 1', () => {
|
|
417
|
+
const schema = number();
|
|
418
|
+
expect(schema._schema).toHaveProperty('ensureIsFinite', true);
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
test('Finite - 2', () => {
|
|
422
|
+
const schema = number().isFinite();
|
|
423
|
+
expect(schema._schema).toHaveProperty('ensureIsFinite', true);
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
test('Finite - 3', () => {
|
|
427
|
+
const schema = number().canBeInfinite();
|
|
428
|
+
expect(schema._schema).toHaveProperty('ensureIsFinite', false);
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
test('Finite - 4', () => {
|
|
432
|
+
const schema1 = number();
|
|
433
|
+
const schema2 = schema1.isFinite();
|
|
434
|
+
const equal = (schema1 as any) === schema2;
|
|
435
|
+
expect(equal).toEqual(true);
|
|
436
|
+
expect(schema1._schema).toHaveProperty('ensureIsFinite', true);
|
|
437
|
+
expect(schema2._schema).toHaveProperty('ensureIsFinite', true);
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
test('Finite - 5', () => {
|
|
441
|
+
const schema1 = number().isFinite();
|
|
442
|
+
const schema2 = schema1.isFinite();
|
|
443
|
+
const equal = (schema1 as any) === schema2;
|
|
444
|
+
expect(equal).toEqual(true);
|
|
445
|
+
expect(schema1._schema).toHaveProperty('ensureIsFinite', true);
|
|
446
|
+
expect(schema2._schema).toHaveProperty('ensureIsFinite', true);
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
test('Finite - 6', () => {
|
|
450
|
+
const schema1 = number();
|
|
451
|
+
const schema2 = schema1.canBeInfinite();
|
|
452
|
+
const equal = (schema1 as any) === schema2;
|
|
453
|
+
expect(equal).toEqual(false);
|
|
454
|
+
expect(schema1._schema).toHaveProperty('ensureIsFinite', true);
|
|
455
|
+
expect(schema2._schema).toHaveProperty('ensureIsFinite', false);
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
test('Finite - 7', () => {
|
|
459
|
+
const schema1 = number().canBeInfinite();
|
|
460
|
+
const schema2 = schema1.canBeInfinite();
|
|
461
|
+
const equal = (schema1 as any) === schema2;
|
|
462
|
+
expect(equal).toEqual(true);
|
|
463
|
+
expect(schema1._schema).toHaveProperty('ensureIsFinite', false);
|
|
464
|
+
expect(schema2._schema).toHaveProperty('ensureIsFinite', false);
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
test('Finite - 8', () => {
|
|
468
|
+
const schema1 = number().canBeInfinite();
|
|
469
|
+
const schema2 = schema1.isFinite();
|
|
470
|
+
const equal = (schema1 as any) === schema2;
|
|
471
|
+
expect(equal).toEqual(false);
|
|
472
|
+
expect(schema1._schema).toHaveProperty('ensureIsFinite', false);
|
|
473
|
+
expect(schema2._schema).toHaveProperty('ensureIsFinite', true);
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
test('Clone', () => {
|
|
477
|
+
const schema1 = number()
|
|
478
|
+
.canBeInfinite()
|
|
479
|
+
.min(20)
|
|
480
|
+
.max(30)
|
|
481
|
+
.addValidator(() => ({ valid: true }))
|
|
482
|
+
.canBeNotInteger()
|
|
483
|
+
.canBeInfinite()
|
|
484
|
+
.canBeNaN();
|
|
485
|
+
const schema2 = schema1.clone();
|
|
486
|
+
const equal = (schema1 as any) === schema2;
|
|
487
|
+
expect(equal).toEqual(false);
|
|
488
|
+
const equal2 = deepEqual(
|
|
489
|
+
(schema1 as any)._schema,
|
|
490
|
+
(schema2 as any)._schema
|
|
491
|
+
);
|
|
492
|
+
expect(equal2).toEqual(true);
|
|
493
|
+
});
|