@augment-vir/assert 31.0.0 → 31.0.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/dist/assertions/boolean.d.ts +20 -26
- package/dist/assertions/boolean.js +185 -41
- package/dist/assertions/boundary.d.ts +40 -256
- package/dist/assertions/boundary.js +265 -229
- package/dist/assertions/enum.d.ts +12 -13
- package/dist/assertions/enum.js +98 -20
- package/dist/assertions/equality/entry-equality.d.ts +11 -15
- package/dist/assertions/equality/entry-equality.js +210 -43
- package/dist/assertions/equality/json-equality.d.ts +11 -15
- package/dist/assertions/equality/json-equality.js +144 -43
- package/dist/assertions/equality/simple-equality.d.ts +39 -46
- package/dist/assertions/equality/simple-equality.js +316 -61
- package/dist/assertions/extendable-assertions.d.ts +0 -12
- package/dist/assertions/extendable-assertions.js +0 -12
- package/dist/assertions/http.d.ts +10 -14
- package/dist/assertions/http.js +96 -28
- package/dist/assertions/instance.d.ts +10 -18
- package/dist/assertions/instance.js +92 -26
- package/dist/assertions/keys.d.ts +59 -138
- package/dist/assertions/keys.js +279 -162
- package/dist/assertions/length.d.ts +30 -212
- package/dist/assertions/length.js +117 -175
- package/dist/assertions/nullish.d.ts +8 -20
- package/dist/assertions/nullish.js +85 -27
- package/dist/assertions/numeric.d.ts +67 -81
- package/dist/assertions/numeric.js +564 -133
- package/dist/assertions/output.d.ts +2 -3
- package/dist/assertions/output.js +1 -7
- package/dist/assertions/primitive.d.ts +33 -40
- package/dist/assertions/primitive.js +232 -66
- package/dist/assertions/promise.d.ts +20 -30
- package/dist/assertions/promise.js +244 -53
- package/dist/assertions/regexp.d.ts +12 -14
- package/dist/assertions/regexp.js +84 -21
- package/dist/assertions/runtime-type.d.ts +99 -150
- package/dist/assertions/runtime-type.js +805 -229
- package/dist/assertions/throws.d.ts +24 -25
- package/dist/assertions/throws.js +43 -5
- package/dist/assertions/uuid.d.ts +11 -16
- package/dist/assertions/uuid.js +91 -22
- package/dist/assertions/values.d.ts +81 -210
- package/dist/assertions/values.js +627 -234
- package/dist/augments/guards/assert-wrap.d.ts +7 -4
- package/dist/augments/guards/assert-wrap.js +5 -4
- package/dist/augments/guards/check-wrap.d.ts +7 -5
- package/dist/augments/guards/check-wrap.js +5 -4
- package/dist/augments/guards/check.d.ts +5 -5
- package/dist/augments/guards/check.js +5 -4
- package/dist/augments/guards/wait-until.d.ts +8 -4
- package/dist/augments/guards/wait-until.js +7 -8
- package/dist/guard-types/guard-group.d.ts +5 -2
- package/dist/guard-types/wait-until-function.d.ts +2 -10
- package/dist/guard-types/wait-until-function.js +1 -9
- package/dist/index.d.ts +1 -0
- package/package.json +2 -2
- package/dist/guard-types/assert-wrap-function.d.ts +0 -12
- package/dist/guard-types/assert-wrap-function.js +0 -14
- package/dist/guard-types/check-function.d.ts +0 -14
- package/dist/guard-types/check-function.js +0 -22
- package/dist/guard-types/check-wrap-wrapper-function.d.ts +0 -12
- package/dist/guard-types/check-wrap-wrapper-function.js +0 -19
- package/dist/guard-types/guard-override.d.ts +0 -4
- package/dist/guard-types/guard-override.js +0 -10
|
@@ -1,45 +1,204 @@
|
|
|
1
1
|
import { stringify } from '@augment-vir/core';
|
|
2
2
|
import deepEqual from 'deep-eql';
|
|
3
3
|
import { AssertionError } from '../../augments/assertion.error.js';
|
|
4
|
-
import {
|
|
5
|
-
export function strictEquals(actual, expected, failureMessage) {
|
|
6
|
-
if (actual !== expected) {
|
|
7
|
-
throw new AssertionError(`\n\n${stringify(actual)}\n\ndoes not strictly equal\n\n${stringify(expected)}\n\n`, failureMessage);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
function notStrictEquals(actual, expected, failureMessage) {
|
|
11
|
-
if (actual === expected) {
|
|
12
|
-
throw new AssertionError(`\n\n${stringify(actual)}\n\nstrictly equals\n\n${stringify(expected)}\n\n`, failureMessage);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
function looseEquals(actual, expected, failureMessage) {
|
|
16
|
-
if (actual != expected) {
|
|
17
|
-
throw new AssertionError(`\n\n${stringify(actual)}\n\ndoes not loosely equal\n\n${stringify(expected)}\n\n`, failureMessage);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
function notLooseEquals(actual, expected, failureMessage) {
|
|
21
|
-
if (actual == expected) {
|
|
22
|
-
throw new AssertionError(`\n\n${stringify(actual)}\n\nloosely equals\n\n${stringify(expected)}\n\n`, failureMessage);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
export function deepEquals(actual, expected, failureMessage) {
|
|
26
|
-
if (!deepEqual(actual, expected)) {
|
|
27
|
-
throw new AssertionError(`\n\n${stringify(actual)}\n\ndoes not deeply equal\n\n${stringify(expected)}\n\n`, failureMessage);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
function notDeepEquals(actual, expected, failureMessage) {
|
|
31
|
-
if (deepEqual(actual, expected)) {
|
|
32
|
-
throw new AssertionError(`\n\n${stringify(actual)}\n\ndeeply equals\n\n${stringify(expected)}\n\n`, failureMessage);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
4
|
+
import { createWaitUntil } from '../../guard-types/wait-until-function.js';
|
|
35
5
|
const assertions = {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Asserts that two values are strictly equal (using
|
|
8
|
+
* [`===`](https://developer.mozilla.org/docs/Web/JavaScript/Equality_comparisons_and_sameness#strict_equality_using)).
|
|
9
|
+
*
|
|
10
|
+
* Type guards the first value.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* import {assert} from '@augment-vir/assert';
|
|
16
|
+
*
|
|
17
|
+
* assert.strictEquals('a', 'a'); // passes
|
|
18
|
+
*
|
|
19
|
+
* assert.strictEquals('1', 1); // fails
|
|
20
|
+
*
|
|
21
|
+
* assert.strictEquals({a: 'a'}, {a: 'a'}); // fails
|
|
22
|
+
*
|
|
23
|
+
* const objectExample = {a: 'a'};
|
|
24
|
+
* assert.strictEquals(objectExample, objectExample); // passes
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @throws {@link AssertionError} If both inputs are not strictly equal.
|
|
28
|
+
* @see
|
|
29
|
+
* - {@link assert.notStrictEquals} : the opposite assertion.
|
|
30
|
+
* - {@link assert.looseEquals} : the loose equality assertion.
|
|
31
|
+
*/
|
|
32
|
+
strictEquals(actual, expected, failureMessage) {
|
|
33
|
+
if (actual !== expected) {
|
|
34
|
+
throw new AssertionError(`\n\n${stringify(actual)}\n\ndoes not strictly equal\n\n${stringify(expected)}\n\n`, failureMessage);
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
/**
|
|
38
|
+
* Asserts that two values are _not_ strictly equal (using
|
|
39
|
+
* [`===`](https://developer.mozilla.org/docs/Web/JavaScript/Equality_comparisons_and_sameness#strict_equality_using)).
|
|
40
|
+
*
|
|
41
|
+
* Performs no type guarding.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
*
|
|
45
|
+
* ```ts
|
|
46
|
+
* import {assert} from '@augment-vir/assert';
|
|
47
|
+
*
|
|
48
|
+
* assert.notStrictEquals('a', 'a'); // fails
|
|
49
|
+
*
|
|
50
|
+
* assert.notStrictEquals('1', 1); // passes
|
|
51
|
+
*
|
|
52
|
+
* assert.notStrictEquals({a: 'a'}, {a: 'a'}); // passes
|
|
53
|
+
*
|
|
54
|
+
* const objectExample = {a: 'a'};
|
|
55
|
+
* assert.notStrictEquals(objectExample, objectExample); // fails
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* @throws {@link AssertionError} If both inputs are strictly equal.
|
|
59
|
+
* @see
|
|
60
|
+
* - {@link assert.strictEquals} : the opposite assertion.
|
|
61
|
+
* - {@link assert.notLooseEquals} : the loose equality assertion.
|
|
62
|
+
*/
|
|
63
|
+
notStrictEquals(actual, expected, failureMessage) {
|
|
64
|
+
if (actual === expected) {
|
|
65
|
+
throw new AssertionError(`\n\n${stringify(actual)}\n\nstrictly equals\n\n${stringify(expected)}\n\n`, failureMessage);
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
/**
|
|
69
|
+
* Asserts that two values are loosely equal (using
|
|
70
|
+
* [`==`](https://developer.mozilla.org/docs/Web/JavaScript/Equality_comparisons_and_sameness#loose_equality_using)).
|
|
71
|
+
*
|
|
72
|
+
* Type guards the first value.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
*
|
|
76
|
+
* ```ts
|
|
77
|
+
* import {assert} from '@augment-vir/assert';
|
|
78
|
+
*
|
|
79
|
+
* assert.looseEquals('a', 'a'); // passes
|
|
80
|
+
*
|
|
81
|
+
* assert.looseEquals('1', 1); // passes
|
|
82
|
+
*
|
|
83
|
+
* assert.looseEquals({a: 'a'}, {a: 'a'}); // fails
|
|
84
|
+
*
|
|
85
|
+
* const objectExample = {a: 'a'};
|
|
86
|
+
* assert.looseEquals(objectExample, objectExample); // passes
|
|
87
|
+
* ```
|
|
88
|
+
*
|
|
89
|
+
* @throws {@link AssertionError} If both inputs are not loosely equal.
|
|
90
|
+
* @see
|
|
91
|
+
* - {@link assert.notLooseEquals} : the opposite assertion.
|
|
92
|
+
* - {@link assert.strictEquals} : the strict equality assertion.
|
|
93
|
+
*/
|
|
94
|
+
looseEquals(actual, expected, failureMessage) {
|
|
95
|
+
if (actual != expected) {
|
|
96
|
+
throw new AssertionError(`\n\n${stringify(actual)}\n\ndoes not loosely equal\n\n${stringify(expected)}\n\n`, failureMessage);
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
/**
|
|
100
|
+
* Asserts that two values are _not_ loosely equal (using
|
|
101
|
+
* [`==`](https://developer.mozilla.org/docs/Web/JavaScript/Equality_comparisons_and_sameness#loose_equality_using)).
|
|
102
|
+
*
|
|
103
|
+
* Performs no type guarding.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
*
|
|
107
|
+
* ```ts
|
|
108
|
+
* import {assert} from '@augment-vir/assert';
|
|
109
|
+
*
|
|
110
|
+
* assert.notLooseEquals('a', 'a'); // fails
|
|
111
|
+
*
|
|
112
|
+
* assert.notLooseEquals('1', 1); // fails
|
|
113
|
+
*
|
|
114
|
+
* assert.notLooseEquals({a: 'a'}, {a: 'a'}); // passes
|
|
115
|
+
*
|
|
116
|
+
* const objectExample = {a: 'a'};
|
|
117
|
+
* assert.notLooseEquals(objectExample, objectExample); // fails
|
|
118
|
+
* ```
|
|
119
|
+
*
|
|
120
|
+
* @throws {@link AssertionError} If both inputs are loosely equal.
|
|
121
|
+
* @see
|
|
122
|
+
* - {@link assert.looseEquals} : the opposite assertion.
|
|
123
|
+
* - {@link assert.strictEquals} : the strict equality assertion.
|
|
124
|
+
*/
|
|
125
|
+
notLooseEquals(actual, expected, failureMessage) {
|
|
126
|
+
if (actual == expected) {
|
|
127
|
+
throw new AssertionError(`\n\n${stringify(actual)}\n\nloosely equals\n\n${stringify(expected)}\n\n`, failureMessage);
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
/**
|
|
131
|
+
* Asserts that two values are deeply equal using the
|
|
132
|
+
* [deep-eql](https://www.npmjs.com/package/deep-eql) package.
|
|
133
|
+
*
|
|
134
|
+
* Note that this check may be _expensive_, depending on what values it is passed. Whenever
|
|
135
|
+
* possible, use simpler equality checks instead (see the **see** section below).
|
|
136
|
+
*
|
|
137
|
+
* Type guards the first value.
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
*
|
|
141
|
+
* ```ts
|
|
142
|
+
* import {assert} from '@augment-vir/assert';
|
|
143
|
+
*
|
|
144
|
+
* assert.deepEquals('a', 'a'); // passes
|
|
145
|
+
*
|
|
146
|
+
* assert.deepEquals('1', 1); // fails
|
|
147
|
+
*
|
|
148
|
+
* assert.deepEquals({a: 'a'}, {a: 'a'}); // passes
|
|
149
|
+
*
|
|
150
|
+
* const objectExample = {a: 'a'};
|
|
151
|
+
* assert.deepEquals(objectExample, objectExample); // passes
|
|
152
|
+
* ```
|
|
153
|
+
*
|
|
154
|
+
* @throws {@link AssertionError} If both inputs are not deeply equal.
|
|
155
|
+
* @see
|
|
156
|
+
* - {@link assert.notDeepEquals} : the opposite assertion.
|
|
157
|
+
* - {@link assert.entriesEqual} : a less expensive (but less thorough) deep equality assertion.
|
|
158
|
+
* - {@link assert.jsonEquals} : a less expensive (but less thorough) deep equality assertion.
|
|
159
|
+
*/
|
|
160
|
+
deepEquals(actual, expected, failureMessage) {
|
|
161
|
+
if (!deepEqual(actual, expected)) {
|
|
162
|
+
throw new AssertionError(`\n\n${stringify(actual)}\n\ndoes not deeply equal\n\n${stringify(expected)}\n\n`, failureMessage);
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
/**
|
|
166
|
+
* Asserts that two values are _not_ deeply equal using the
|
|
167
|
+
* [deep-eql](https://www.npmjs.com/package/deep-eql) package.
|
|
168
|
+
*
|
|
169
|
+
* Note that this check may be _expensive_, depending on what values it is passed. Whenever
|
|
170
|
+
* possible, use simpler equality checks instead (see the **see** section below).
|
|
171
|
+
*
|
|
172
|
+
* Type guards the first value.
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
*
|
|
176
|
+
* ```ts
|
|
177
|
+
* import {assert} from '@augment-vir/assert';
|
|
178
|
+
*
|
|
179
|
+
* assert.notDeepEquals('a', 'a'); // false
|
|
180
|
+
*
|
|
181
|
+
* assert.notDeepEquals('1', 1); // passes
|
|
182
|
+
*
|
|
183
|
+
* assert.notDeepEquals({a: 'a'}, {a: 'a'}); // fails
|
|
184
|
+
*
|
|
185
|
+
* const objectExample = {a: 'a'};
|
|
186
|
+
* assert.notDeepEquals(objectExample, objectExample); // fails
|
|
187
|
+
* ```
|
|
188
|
+
*
|
|
189
|
+
* @throws {@link AssertionError} If both inputs are deeply equal.
|
|
190
|
+
* @see
|
|
191
|
+
* - {@link assert.deepEquals} : the opposite assertion.
|
|
192
|
+
* - {@link assert.notEntriesEqual} : a less expensive (but less thorough) deep equality assertion.
|
|
193
|
+
* - {@link assert.notJsonEquals} : a less expensive (but less thorough) deep equality assertion.
|
|
194
|
+
*/
|
|
195
|
+
notDeepEquals(actual, expected, failureMessage) {
|
|
196
|
+
if (deepEqual(actual, expected)) {
|
|
197
|
+
throw new AssertionError(`\n\n${stringify(actual)}\n\ndeeply equals\n\n${stringify(expected)}\n\n`, failureMessage);
|
|
198
|
+
}
|
|
199
|
+
},
|
|
42
200
|
};
|
|
201
|
+
export const deepEquals = assertions.deepEquals;
|
|
43
202
|
export const simpleEqualityGuards = {
|
|
44
203
|
assert: assertions,
|
|
45
204
|
check: {
|
|
@@ -68,7 +227,9 @@ export const simpleEqualityGuards = {
|
|
|
68
227
|
* - {@link check.notStrictEquals} : the opposite check.
|
|
69
228
|
* - {@link check.looseEquals} : the loose equality check.
|
|
70
229
|
*/
|
|
71
|
-
strictEquals
|
|
230
|
+
strictEquals(actual, expected) {
|
|
231
|
+
return actual === expected;
|
|
232
|
+
},
|
|
72
233
|
/**
|
|
73
234
|
* Checks that two values are _not_ strictly equal (using
|
|
74
235
|
* [`===`](https://developer.mozilla.org/docs/Web/JavaScript/Equality_comparisons_and_sameness#strict_equality_using)).
|
|
@@ -94,7 +255,9 @@ export const simpleEqualityGuards = {
|
|
|
94
255
|
* - {@link check.strictEquals} : the opposite check.
|
|
95
256
|
* - {@link check.notLooseEquals} : the loose equality check.
|
|
96
257
|
*/
|
|
97
|
-
notStrictEquals
|
|
258
|
+
notStrictEquals(actual, expected) {
|
|
259
|
+
return actual !== expected;
|
|
260
|
+
},
|
|
98
261
|
/**
|
|
99
262
|
* Checks that two values are loosely equal (using
|
|
100
263
|
* [`==`](https://developer.mozilla.org/docs/Web/JavaScript/Equality_comparisons_and_sameness#loose_equality_using)).
|
|
@@ -120,7 +283,9 @@ export const simpleEqualityGuards = {
|
|
|
120
283
|
* - {@link check.notLooseEquals} : the opposite check.
|
|
121
284
|
* - {@link check.strictEquals} : the strict equality check.
|
|
122
285
|
*/
|
|
123
|
-
looseEquals
|
|
286
|
+
looseEquals(actual, expected) {
|
|
287
|
+
return actual == expected;
|
|
288
|
+
},
|
|
124
289
|
/**
|
|
125
290
|
* Checks that two values are _not_ loosely equal (using
|
|
126
291
|
* [`==`](https://developer.mozilla.org/docs/Web/JavaScript/Equality_comparisons_and_sameness#loose_equality_using)).
|
|
@@ -146,7 +311,9 @@ export const simpleEqualityGuards = {
|
|
|
146
311
|
* - {@link check.looseEquals} : the opposite check.
|
|
147
312
|
* - {@link check.strictEquals} : the strict equality check.
|
|
148
313
|
*/
|
|
149
|
-
notLooseEquals
|
|
314
|
+
notLooseEquals(actual, expected) {
|
|
315
|
+
return actual != expected;
|
|
316
|
+
},
|
|
150
317
|
/**
|
|
151
318
|
* Checks that two values are deeply equal using the
|
|
152
319
|
* [deep-eql](https://www.npmjs.com/package/deep-eql) package.
|
|
@@ -176,7 +343,9 @@ export const simpleEqualityGuards = {
|
|
|
176
343
|
* - {@link check.entriesEqual} : a less expensive (but less thorough) deep equality check.
|
|
177
344
|
* - {@link check.jsonEquals} : a less expensive (but less thorough) deep equality check.
|
|
178
345
|
*/
|
|
179
|
-
deepEquals
|
|
346
|
+
deepEquals(actual, expected) {
|
|
347
|
+
return deepEqual(actual, expected);
|
|
348
|
+
},
|
|
180
349
|
/**
|
|
181
350
|
* Checks that two values are _not_ deeply equal using the
|
|
182
351
|
* [deep-eql](https://www.npmjs.com/package/deep-eql) package.
|
|
@@ -206,7 +375,9 @@ export const simpleEqualityGuards = {
|
|
|
206
375
|
* - {@link check.entriesEqual} : a less expensive (but less thorough) deep equality check.
|
|
207
376
|
* - {@link check.jsonEquals} : a less expensive (but less thorough) deep equality check.
|
|
208
377
|
*/
|
|
209
|
-
notDeepEquals
|
|
378
|
+
notDeepEquals(actual, expected) {
|
|
379
|
+
return !deepEqual(actual, expected);
|
|
380
|
+
},
|
|
210
381
|
},
|
|
211
382
|
assertWrap: {
|
|
212
383
|
/**
|
|
@@ -236,7 +407,14 @@ export const simpleEqualityGuards = {
|
|
|
236
407
|
* - {@link assertWrap.notStrictEquals} : the opposite assertion.
|
|
237
408
|
* - {@link assertWrap.looseEquals} : the loose equality assertion.
|
|
238
409
|
*/
|
|
239
|
-
strictEquals
|
|
410
|
+
strictEquals(actual, expected, failureMessage) {
|
|
411
|
+
if (actual === expected) {
|
|
412
|
+
return actual;
|
|
413
|
+
}
|
|
414
|
+
else {
|
|
415
|
+
throw new AssertionError(`\n\n${stringify(actual)}\n\ndoes not strictly equal\n\n${stringify(expected)}\n\n`, failureMessage);
|
|
416
|
+
}
|
|
417
|
+
},
|
|
240
418
|
/**
|
|
241
419
|
* Asserts that two values are _not_ strictly equal (using
|
|
242
420
|
* [`===`](https://developer.mozilla.org/docs/Web/JavaScript/Equality_comparisons_and_sameness#strict_equality_using)).
|
|
@@ -264,7 +442,14 @@ export const simpleEqualityGuards = {
|
|
|
264
442
|
* - {@link assertWrap.strictEquals} : the opposite assertion.
|
|
265
443
|
* - {@link assertWrap.notLooseEquals} : the loose equality assertion.
|
|
266
444
|
*/
|
|
267
|
-
notStrictEquals
|
|
445
|
+
notStrictEquals(actual, expected, failureMessage) {
|
|
446
|
+
if (actual === expected) {
|
|
447
|
+
throw new AssertionError(`\n\n${stringify(actual)}\n\nstrictly equals\n\n${stringify(expected)}\n\n`, failureMessage);
|
|
448
|
+
}
|
|
449
|
+
else {
|
|
450
|
+
return actual;
|
|
451
|
+
}
|
|
452
|
+
},
|
|
268
453
|
/**
|
|
269
454
|
* Asserts that two values are loosely equal (using
|
|
270
455
|
* [`==`](https://developer.mozilla.org/docs/Web/JavaScript/Equality_comparisons_and_sameness#loose_equality_using)).
|
|
@@ -292,7 +477,14 @@ export const simpleEqualityGuards = {
|
|
|
292
477
|
* - {@link assertWrap.notLooseEquals} : the opposite assertion.
|
|
293
478
|
* - {@link assertWrap.strictEquals} : the strict equality assertion.
|
|
294
479
|
*/
|
|
295
|
-
looseEquals
|
|
480
|
+
looseEquals(actual, expected, failureMessage) {
|
|
481
|
+
if (actual == expected) {
|
|
482
|
+
return actual;
|
|
483
|
+
}
|
|
484
|
+
else {
|
|
485
|
+
throw new AssertionError(`\n\n${stringify(actual)}\n\ndoes not loosely equal\n\n${stringify(expected)}\n\n`, failureMessage);
|
|
486
|
+
}
|
|
487
|
+
},
|
|
296
488
|
/**
|
|
297
489
|
* Asserts that two values are _not_ loosely equal (using
|
|
298
490
|
* [`==`](https://developer.mozilla.org/docs/Web/JavaScript/Equality_comparisons_and_sameness#loose_equality_using)).
|
|
@@ -320,7 +512,14 @@ export const simpleEqualityGuards = {
|
|
|
320
512
|
* - {@link assertWrap.looseEquals} : the opposite assertion.
|
|
321
513
|
* - {@link assertWrap.strictEquals} : the strict equality assertion.
|
|
322
514
|
*/
|
|
323
|
-
notLooseEquals
|
|
515
|
+
notLooseEquals(actual, expected, failureMessage) {
|
|
516
|
+
if (actual == expected) {
|
|
517
|
+
throw new AssertionError(`\n\n${stringify(actual)}\n\nloosely equals\n\n${stringify(expected)}\n\n`, failureMessage);
|
|
518
|
+
}
|
|
519
|
+
else {
|
|
520
|
+
return actual;
|
|
521
|
+
}
|
|
522
|
+
},
|
|
324
523
|
/**
|
|
325
524
|
* Asserts that two values are deeply equal using the
|
|
326
525
|
* [deep-eql](https://www.npmjs.com/package/deep-eql) package. Returns the first value if
|
|
@@ -352,7 +551,14 @@ export const simpleEqualityGuards = {
|
|
|
352
551
|
* - {@link assertWrap.entriesEqual} : a less expensive (but less thorough) deep equality assertion.
|
|
353
552
|
* - {@link assertWrap.jsonEquals} : a less expensive (but less thorough) deep equality assertion.
|
|
354
553
|
*/
|
|
355
|
-
deepEquals
|
|
554
|
+
deepEquals(actual, expected, failureMessage) {
|
|
555
|
+
if (deepEqual(actual, expected)) {
|
|
556
|
+
return actual;
|
|
557
|
+
}
|
|
558
|
+
else {
|
|
559
|
+
throw new AssertionError(`\n\n${stringify(actual)}\n\ndoes not deeply equal\n\n${stringify(expected)}\n\n`, failureMessage);
|
|
560
|
+
}
|
|
561
|
+
},
|
|
356
562
|
/**
|
|
357
563
|
* Asserts that two values are _not_ deeply equal using the
|
|
358
564
|
* [deep-eql](https://www.npmjs.com/package/deep-eql) package. Returns the first value if
|
|
@@ -384,7 +590,14 @@ export const simpleEqualityGuards = {
|
|
|
384
590
|
* - {@link assertWrap.entriesEqual} : a less expensive (but less thorough) deep equality assertion.
|
|
385
591
|
* - {@link assertWrap.jsonEquals} : a less expensive (but less thorough) deep equality assertion.
|
|
386
592
|
*/
|
|
387
|
-
notDeepEquals
|
|
593
|
+
notDeepEquals(actual, expected, failureMessage) {
|
|
594
|
+
if (deepEqual(actual, expected)) {
|
|
595
|
+
throw new AssertionError(`\n\n${stringify(actual)}\n\ndeeply equals\n\n${stringify(expected)}\n\n`, failureMessage);
|
|
596
|
+
}
|
|
597
|
+
else {
|
|
598
|
+
return actual;
|
|
599
|
+
}
|
|
600
|
+
},
|
|
388
601
|
},
|
|
389
602
|
checkWrap: {
|
|
390
603
|
/**
|
|
@@ -414,7 +627,14 @@ export const simpleEqualityGuards = {
|
|
|
414
627
|
* - {@link checkWrap.notStrictEquals} : the opposite check.
|
|
415
628
|
* - {@link checkWrap.looseEquals} : the loose equality check.
|
|
416
629
|
*/
|
|
417
|
-
strictEquals
|
|
630
|
+
strictEquals(actual, expected) {
|
|
631
|
+
if (actual === expected) {
|
|
632
|
+
return actual;
|
|
633
|
+
}
|
|
634
|
+
else {
|
|
635
|
+
return undefined;
|
|
636
|
+
}
|
|
637
|
+
},
|
|
418
638
|
/**
|
|
419
639
|
* Checks that two values are _not_ strictly equal (using
|
|
420
640
|
* [`===`](https://developer.mozilla.org/docs/Web/JavaScript/Equality_comparisons_and_sameness#strict_equality_using)).
|
|
@@ -442,7 +662,14 @@ export const simpleEqualityGuards = {
|
|
|
442
662
|
* - {@link checkWrap.strictEquals} : the opposite check.
|
|
443
663
|
* - {@link checkWrap.notLooseEquals} : the loose equality check.
|
|
444
664
|
*/
|
|
445
|
-
notStrictEquals
|
|
665
|
+
notStrictEquals(actual, expected) {
|
|
666
|
+
if (actual === expected) {
|
|
667
|
+
return undefined;
|
|
668
|
+
}
|
|
669
|
+
else {
|
|
670
|
+
return actual;
|
|
671
|
+
}
|
|
672
|
+
},
|
|
446
673
|
/**
|
|
447
674
|
* Checks that two values are loosely equal (using
|
|
448
675
|
* [`==`](https://developer.mozilla.org/docs/Web/JavaScript/Equality_comparisons_and_sameness#loose_equality_using)).
|
|
@@ -470,7 +697,14 @@ export const simpleEqualityGuards = {
|
|
|
470
697
|
* - {@link checkWrap.notLooseEquals} : the opposite check.
|
|
471
698
|
* - {@link checkWrap.strictEquals} : the strict equality check.
|
|
472
699
|
*/
|
|
473
|
-
looseEquals
|
|
700
|
+
looseEquals(actual, expected) {
|
|
701
|
+
if (actual == expected) {
|
|
702
|
+
return actual;
|
|
703
|
+
}
|
|
704
|
+
else {
|
|
705
|
+
return undefined;
|
|
706
|
+
}
|
|
707
|
+
},
|
|
474
708
|
/**
|
|
475
709
|
* Checks that two values are _not_ loosely equal (using
|
|
476
710
|
* [`==`](https://developer.mozilla.org/docs/Web/JavaScript/Equality_comparisons_and_sameness#loose_equality_using)).
|
|
@@ -498,7 +732,14 @@ export const simpleEqualityGuards = {
|
|
|
498
732
|
* - {@link checkWrap.looseEquals} : the opposite check.
|
|
499
733
|
* - {@link checkWrap.strictEquals} : the strict equality check.
|
|
500
734
|
*/
|
|
501
|
-
notLooseEquals
|
|
735
|
+
notLooseEquals(actual, expected) {
|
|
736
|
+
if (actual === expected) {
|
|
737
|
+
return undefined;
|
|
738
|
+
}
|
|
739
|
+
else {
|
|
740
|
+
return actual;
|
|
741
|
+
}
|
|
742
|
+
},
|
|
502
743
|
/**
|
|
503
744
|
* Checks that two values are deeply equal using the
|
|
504
745
|
* [deep-eql](https://www.npmjs.com/package/deep-eql) package. Returns the first value if
|
|
@@ -530,7 +771,14 @@ export const simpleEqualityGuards = {
|
|
|
530
771
|
* - {@link checkWrap.entriesEqual} : a less expensive (but less thorough) deep equality check.
|
|
531
772
|
* - {@link checkWrap.jsonEquals} : a less expensive (but less thorough) deep equality check.
|
|
532
773
|
*/
|
|
533
|
-
deepEquals
|
|
774
|
+
deepEquals(actual, expected) {
|
|
775
|
+
if (deepEqual(actual, expected)) {
|
|
776
|
+
return actual;
|
|
777
|
+
}
|
|
778
|
+
else {
|
|
779
|
+
return undefined;
|
|
780
|
+
}
|
|
781
|
+
},
|
|
534
782
|
/**
|
|
535
783
|
* Checks that two values are _not_ deeply equal using the
|
|
536
784
|
* [deep-eql](https://www.npmjs.com/package/deep-eql) package. Returns the first value if
|
|
@@ -562,7 +810,14 @@ export const simpleEqualityGuards = {
|
|
|
562
810
|
* - {@link checkWrap.entriesEqual} : a less expensive (but less thorough) deep equality check.
|
|
563
811
|
* - {@link checkWrap.jsonEquals} : a less expensive (but less thorough) deep equality check.
|
|
564
812
|
*/
|
|
565
|
-
notDeepEquals
|
|
813
|
+
notDeepEquals(actual, expected) {
|
|
814
|
+
if (deepEqual(actual, expected)) {
|
|
815
|
+
return undefined;
|
|
816
|
+
}
|
|
817
|
+
else {
|
|
818
|
+
return actual;
|
|
819
|
+
}
|
|
820
|
+
},
|
|
566
821
|
},
|
|
567
822
|
waitUntil: {
|
|
568
823
|
/**
|
|
@@ -596,7 +851,7 @@ export const simpleEqualityGuards = {
|
|
|
596
851
|
* - {@link waitUntil.notStrictEquals} : the opposite assertion.
|
|
597
852
|
* - {@link waitUntil.looseEquals} : the loose equality assertion.
|
|
598
853
|
*/
|
|
599
|
-
strictEquals:
|
|
854
|
+
strictEquals: createWaitUntil(assertions.strictEquals),
|
|
600
855
|
/**
|
|
601
856
|
* Repeatedly calls a callback until its output does _not_ strictly equal (using
|
|
602
857
|
* [`===`](https://developer.mozilla.org/docs/Web/JavaScript/Equality_comparisons_and_sameness#strict_equality_using))
|
|
@@ -628,7 +883,7 @@ export const simpleEqualityGuards = {
|
|
|
628
883
|
* - {@link waitUntil.strictEquals} : the opposite assertion.
|
|
629
884
|
* - {@link waitUntil.notLooseEquals} : the loose equality assertion.
|
|
630
885
|
*/
|
|
631
|
-
notStrictEquals:
|
|
886
|
+
notStrictEquals: createWaitUntil(assertions.notStrictEquals),
|
|
632
887
|
/**
|
|
633
888
|
* Repeatedly calls a callback until its output loosely equals (using
|
|
634
889
|
* [`==`](https://developer.mozilla.org/docs/Web/JavaScript/Equality_comparisons_and_sameness#loose_equality_using))
|
|
@@ -660,7 +915,7 @@ export const simpleEqualityGuards = {
|
|
|
660
915
|
* - {@link waitUntil.notLooseEquals} : the opposite assertion.
|
|
661
916
|
* - {@link waitUntil.strictEquals} : the strict equality assertion.
|
|
662
917
|
*/
|
|
663
|
-
looseEquals:
|
|
918
|
+
looseEquals: createWaitUntil(assertions.looseEquals),
|
|
664
919
|
/**
|
|
665
920
|
* Repeatedly calls a callback until its output does _not_ loosely equal (using
|
|
666
921
|
* [`==`](https://developer.mozilla.org/docs/Web/JavaScript/Equality_comparisons_and_sameness#loose_equality_using))
|
|
@@ -692,7 +947,7 @@ export const simpleEqualityGuards = {
|
|
|
692
947
|
* - {@link waitUntil.looseEquals} : the opposite assertion.
|
|
693
948
|
* - {@link waitUntil.notStrictEquals} : the strict equality assertion.
|
|
694
949
|
*/
|
|
695
|
-
notLooseEquals:
|
|
950
|
+
notLooseEquals: createWaitUntil(assertions.notLooseEquals),
|
|
696
951
|
/**
|
|
697
952
|
* Repeatedly calls a callback until its output deeply equals (using the
|
|
698
953
|
* [deep-eql](https://www.npmjs.com/package/deep-eql) package) the first input. Once the
|
|
@@ -727,7 +982,7 @@ export const simpleEqualityGuards = {
|
|
|
727
982
|
* - {@link waitUntil.entriesEqual} : a less expensive (but less thorough) deep equality assertion.
|
|
728
983
|
* - {@link waitUntil.jsonEquals} : a less expensive (but less thorough) deep equality assertion.
|
|
729
984
|
*/
|
|
730
|
-
deepEquals:
|
|
985
|
+
deepEquals: createWaitUntil(assertions.deepEquals),
|
|
731
986
|
/**
|
|
732
987
|
* Repeatedly calls a callback until its output does _not_ deeply equal (using the
|
|
733
988
|
* [deep-eql](https://www.npmjs.com/package/deep-eql) package) the first input. Once the
|
|
@@ -762,6 +1017,6 @@ export const simpleEqualityGuards = {
|
|
|
762
1017
|
* - {@link waitUntil.entriesEqual} : a less expensive (but less thorough) deep equality assertion.
|
|
763
1018
|
* - {@link waitUntil.jsonEquals} : a less expensive (but less thorough) deep equality assertion.
|
|
764
1019
|
*/
|
|
765
|
-
notDeepEquals:
|
|
1020
|
+
notDeepEquals: createWaitUntil(assertions.notDeepEquals),
|
|
766
1021
|
},
|
|
767
1022
|
};
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type { ArrayElement } from '@augment-vir/core';
|
|
2
|
-
import type { UnionToIntersection } from 'type-fest';
|
|
3
1
|
import { booleanGuards } from './boolean.js';
|
|
4
2
|
import { boundaryGuards } from './boundary.js';
|
|
5
3
|
import { enumGuards } from './enum.js';
|
|
@@ -47,13 +45,3 @@ export declare const guardOverrides: [
|
|
|
47
45
|
typeof httpGuards,
|
|
48
46
|
typeof outputGuards
|
|
49
47
|
];
|
|
50
|
-
export declare const checkOverrides: UnionToIntersection<ArrayElement<typeof guardOverrides>['check']>;
|
|
51
|
-
export declare const assertWrapOverrides: UnionToIntersection<Extract<ArrayElement<typeof guardOverrides>, {
|
|
52
|
-
assertWrap: any;
|
|
53
|
-
}>['assertWrap']>;
|
|
54
|
-
export declare const checkWrapOverrides: UnionToIntersection<Extract<ArrayElement<typeof guardOverrides>, {
|
|
55
|
-
checkWrap: any;
|
|
56
|
-
}>['checkWrap']>;
|
|
57
|
-
export declare const waitUntilOverrides: UnionToIntersection<Extract<ArrayElement<typeof guardOverrides>, {
|
|
58
|
-
waitUntil: any;
|
|
59
|
-
}>['waitUntil']>;
|
|
@@ -66,15 +66,3 @@ export const guardOverrides = [
|
|
|
66
66
|
httpGuards,
|
|
67
67
|
outputGuards,
|
|
68
68
|
];
|
|
69
|
-
export const checkOverrides = Object.assign({}, ...guardOverrides.map((entry) => {
|
|
70
|
-
return entry.check;
|
|
71
|
-
}));
|
|
72
|
-
export const assertWrapOverrides = Object.assign({}, ...guardOverrides.map((entry) => {
|
|
73
|
-
return entry.assertWrap;
|
|
74
|
-
}));
|
|
75
|
-
export const checkWrapOverrides = Object.assign({}, ...guardOverrides.map((entry) => {
|
|
76
|
-
return entry.checkWrap;
|
|
77
|
-
}));
|
|
78
|
-
export const waitUntilOverrides = Object.assign({}, ...guardOverrides.map((entry) => {
|
|
79
|
-
return entry.waitUntil;
|
|
80
|
-
}));
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { HttpStatus, type HttpStatusByCategory, type HttpStatusCategory, type MaybePromise, type NarrowToExpected } from '@augment-vir/core';
|
|
2
|
-
import { autoGuardSymbol } from '../guard-types/guard-override.js';
|
|
3
2
|
import { type WaitUntilOptions } from '../guard-types/wait-until-function.js';
|
|
4
|
-
declare function isHttpStatus(actual: unknown, failureMessage?: string | undefined): asserts actual is HttpStatus;
|
|
5
|
-
declare function isHttpStatusCategory<const Actual, const Category extends HttpStatusCategory>(actual: Actual, category: Category, failureMessage?: string | undefined): asserts actual is NarrowToExpected<Actual, HttpStatusByCategory<Category>>;
|
|
6
3
|
export declare const httpGuards: {
|
|
7
4
|
assert: {
|
|
8
5
|
/**
|
|
@@ -26,7 +23,7 @@ export declare const httpGuards: {
|
|
|
26
23
|
* - {@link HttpStatus} : all included statuses.
|
|
27
24
|
* - {@link HttpStatusCategory} : all status categories.
|
|
28
25
|
*/
|
|
29
|
-
isHttpStatus:
|
|
26
|
+
isHttpStatus<Actual>(this: void, actual: unknown, failureMessage?: string | undefined): asserts actual is NarrowToExpected<Actual, HttpStatus>;
|
|
30
27
|
/**
|
|
31
28
|
* Asserts that a value is an {@link HttpStatus} within a specific {@link HttpStatusCategory}.
|
|
32
29
|
*
|
|
@@ -49,7 +46,7 @@ export declare const httpGuards: {
|
|
|
49
46
|
* - {@link HttpStatus} : all included statuses.
|
|
50
47
|
* - {@link HttpStatusCategory} : all status categories.
|
|
51
48
|
*/
|
|
52
|
-
isHttpStatusCategory:
|
|
49
|
+
isHttpStatusCategory<const Actual, const Category extends HttpStatusCategory>(this: void, actual: Actual, category: Category, failureMessage?: string | undefined): asserts actual is NarrowToExpected<Actual, HttpStatusByCategory<Category>>;
|
|
53
50
|
};
|
|
54
51
|
check: {
|
|
55
52
|
/**
|
|
@@ -72,7 +69,7 @@ export declare const httpGuards: {
|
|
|
72
69
|
* - {@link HttpStatus} : all included statuses.
|
|
73
70
|
* - {@link HttpStatusCategory} : all status categories.
|
|
74
71
|
*/
|
|
75
|
-
isHttpStatus:
|
|
72
|
+
isHttpStatus<Actual>(this: void, actual: Actual): actual is NarrowToExpected<Actual, HttpStatus>;
|
|
76
73
|
/**
|
|
77
74
|
* Checks that a value is an {@link HttpStatus} within a specific {@link HttpStatusCategory}.
|
|
78
75
|
*
|
|
@@ -93,7 +90,7 @@ export declare const httpGuards: {
|
|
|
93
90
|
* - {@link HttpStatus} : all included statuses.
|
|
94
91
|
* - {@link HttpStatusCategory} : all status categories.
|
|
95
92
|
*/
|
|
96
|
-
isHttpStatusCategory
|
|
93
|
+
isHttpStatusCategory<const Actual, const Category extends HttpStatusCategory>(this: void, actual: Actual, category: Category): actual is NarrowToExpected<Actual, HttpStatusByCategory<Category>>;
|
|
97
94
|
};
|
|
98
95
|
assertWrap: {
|
|
99
96
|
/**
|
|
@@ -117,7 +114,7 @@ export declare const httpGuards: {
|
|
|
117
114
|
* - {@link HttpStatus} : all included statuses.
|
|
118
115
|
* - {@link HttpStatusCategory} : all status categories.
|
|
119
116
|
*/
|
|
120
|
-
isHttpStatus:
|
|
117
|
+
isHttpStatus<Actual>(this: void, actual: Actual, failureMessage?: string | undefined): NarrowToExpected<Actual, HttpStatus>;
|
|
121
118
|
/**
|
|
122
119
|
* Checks that a value is an {@link HttpStatus} within a specific {@link HttpStatusCategory}.
|
|
123
120
|
* Returns the value if the assertion passes.
|
|
@@ -139,7 +136,7 @@ export declare const httpGuards: {
|
|
|
139
136
|
* - {@link HttpStatus} : all included statuses.
|
|
140
137
|
* - {@link HttpStatusCategory} : all status categories.
|
|
141
138
|
*/
|
|
142
|
-
isHttpStatusCategory
|
|
139
|
+
isHttpStatusCategory<const Actual, const Category extends HttpStatusCategory>(this: void, actual: Actual, category: Category, failureMessage?: string | undefined): NarrowToExpected<Actual, HttpStatusByCategory<Category>>;
|
|
143
140
|
};
|
|
144
141
|
checkWrap: {
|
|
145
142
|
/**
|
|
@@ -164,7 +161,7 @@ export declare const httpGuards: {
|
|
|
164
161
|
* - {@link HttpStatus} : all included statuses.
|
|
165
162
|
* - {@link HttpStatusCategory} : all status categories.
|
|
166
163
|
*/
|
|
167
|
-
isHttpStatus:
|
|
164
|
+
isHttpStatus<Actual>(this: void, actual: Actual): NarrowToExpected<Actual, HttpStatus> | undefined;
|
|
168
165
|
/**
|
|
169
166
|
* Checks that a value is an {@link HttpStatus} within a specific {@link HttpStatusCategory}.
|
|
170
167
|
* Returns the value if the check passes, otherwise `undefined`.
|
|
@@ -186,7 +183,7 @@ export declare const httpGuards: {
|
|
|
186
183
|
* - {@link HttpStatus} : all included statuses.
|
|
187
184
|
* - {@link HttpStatusCategory} : all status categories.
|
|
188
185
|
*/
|
|
189
|
-
isHttpStatusCategory
|
|
186
|
+
isHttpStatusCategory<const Actual, const Category extends HttpStatusCategory>(this: void, actual: Actual, category: Category): NarrowToExpected<Actual, HttpStatusByCategory<Category>> | undefined;
|
|
190
187
|
};
|
|
191
188
|
waitUntil: {
|
|
192
189
|
/**
|
|
@@ -212,7 +209,7 @@ export declare const httpGuards: {
|
|
|
212
209
|
* - {@link HttpStatus} : all included statuses.
|
|
213
210
|
* - {@link HttpStatusCategory} : all status categories.
|
|
214
211
|
*/
|
|
215
|
-
isHttpStatus:
|
|
212
|
+
isHttpStatus: <const Actual>(this: void, callback: () => MaybePromise<Actual>, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined) => Promise<NarrowToExpected<Actual, HttpStatus>>;
|
|
216
213
|
/**
|
|
217
214
|
* Repeatedly calls a callback until its output is an {@link HttpStatus} within a specific
|
|
218
215
|
* {@link HttpStatusCategory}. Once the callback output passes, it is returned. If the
|
|
@@ -237,7 +234,6 @@ export declare const httpGuards: {
|
|
|
237
234
|
* - {@link HttpStatus} : all included statuses.
|
|
238
235
|
* - {@link HttpStatusCategory} : all status categories.
|
|
239
236
|
*/
|
|
240
|
-
isHttpStatusCategory: <const Actual, const Category extends HttpStatusCategory>(category: Category, callback: () => MaybePromise<Actual>, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined) => Promise<NarrowToExpected<Actual, HttpStatusByCategory<Category>>>;
|
|
237
|
+
isHttpStatusCategory: <const Actual, const Category extends HttpStatusCategory>(this: void, category: Category, callback: () => MaybePromise<Actual>, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined) => Promise<NarrowToExpected<Actual, HttpStatusByCategory<Category>>>;
|
|
241
238
|
};
|
|
242
239
|
};
|
|
243
|
-
export {};
|