@augment-vir/assert 30.0.0 → 30.0.2
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 +11 -0
- package/dist/assertions/boolean.d.ts +443 -17
- package/dist/assertions/boolean.js +365 -8
- package/dist/assertions/boundary.d.ts +657 -13
- package/dist/assertions/boundary.js +537 -5
- package/dist/assertions/enum.d.ts +236 -8
- package/dist/assertions/enum.js +197 -5
- package/dist/assertions/equality/entry-equality.d.ts +287 -11
- package/dist/assertions/equality/entry-equality.js +243 -6
- package/dist/assertions/equality/json-equality.d.ts +244 -15
- package/dist/assertions/equality/json-equality.js +207 -11
- package/dist/assertions/equality/simple-equality.d.ts +849 -28
- package/dist/assertions/equality/simple-equality.js +712 -6
- package/dist/assertions/equality/ts-type-equality.d.ts +37 -1
- package/dist/assertions/equality/ts-type-equality.js +13 -1
- package/dist/assertions/extendable-assertions.d.ts +288 -120
- package/dist/assertions/extendable-assertions.js +32 -60
- package/dist/assertions/http.d.ts +217 -10
- package/dist/assertions/http.js +182 -6
- package/dist/assertions/instance.d.ts +189 -8
- package/dist/assertions/instance.js +159 -5
- package/dist/assertions/keys.d.ts +658 -13
- package/dist/assertions/keys.js +556 -5
- package/dist/assertions/length.d.ts +381 -9
- package/dist/assertions/length.js +309 -5
- package/dist/assertions/nullish.d.ts +169 -7
- package/dist/assertions/nullish.js +137 -6
- package/dist/assertions/numeric.d.ts +965 -11
- package/dist/assertions/numeric.js +819 -1
- package/dist/assertions/output.d.ts +107 -7
- package/dist/assertions/output.js +92 -5
- package/dist/assertions/primitive.d.ts +416 -13
- package/dist/assertions/primitive.js +352 -6
- package/dist/assertions/promise.d.ts +640 -21
- package/dist/assertions/promise.js +536 -15
- package/dist/assertions/regexp.d.ts +202 -3
- package/dist/assertions/regexp.js +173 -1
- package/dist/assertions/runtime-type.d.ts +1822 -41
- package/dist/assertions/runtime-type.js +1558 -35
- package/dist/assertions/throws.d.ts +265 -17
- package/dist/assertions/throws.js +229 -17
- package/dist/assertions/uuid.d.ts +233 -10
- package/dist/assertions/uuid.js +195 -6
- package/dist/assertions/values.d.ts +1086 -15
- package/dist/assertions/values.js +907 -6
- package/dist/augments/assertion.error.d.ts +2 -1
- package/dist/augments/assertion.error.js +2 -1
- package/dist/augments/guards/assert-wrap.d.ts +82 -37
- package/dist/augments/guards/assert-wrap.js +13 -2
- package/dist/augments/guards/assert.d.ts +30 -14
- package/dist/augments/guards/assert.js +21 -4
- package/dist/augments/guards/check-wrap.d.ts +94 -51
- package/dist/augments/guards/check-wrap.js +11 -3
- package/dist/augments/guards/check.d.ts +87 -37
- package/dist/augments/guards/check.js +9 -2
- package/dist/augments/guards/wait-until.d.ts +110 -103
- package/dist/augments/guards/wait-until.js +18 -3
- package/dist/augments/if-equals.d.ts +4 -2
- package/dist/guard-types/assert-wrap-function.d.ts +5 -2
- package/dist/guard-types/check-function.d.ts +5 -2
- package/dist/guard-types/check-wrap-wrapper-function.d.ts +4 -1
- package/dist/guard-types/guard-group.d.ts +7 -8
- package/dist/guard-types/wait-until-function.d.ts +8 -3
- package/dist/guard-types/wait-until-function.js +1 -1
- package/package.json +21 -8
|
@@ -1,40 +1,316 @@
|
|
|
1
1
|
import type { NarrowToExpected } from '@augment-vir/core';
|
|
2
2
|
import { MaybePromise } from '@augment-vir/core';
|
|
3
|
+
import { autoGuardSymbol } from '../../guard-types/guard-override.js';
|
|
3
4
|
import { WaitUntilOptions } from '../../guard-types/wait-until-function.js';
|
|
4
5
|
declare function entriesEqual<const Actual extends object, const Expected extends Actual>(actual: Actual, expected: Expected, failureMessage?: string | undefined): asserts actual is Expected;
|
|
5
6
|
declare function notEntriesEqual(actual: object, expected: object, failureMessage?: string | undefined): void;
|
|
6
7
|
export declare const entryEqualityGuards: {
|
|
7
|
-
|
|
8
|
+
assert: {
|
|
8
9
|
/**
|
|
9
|
-
*
|
|
10
|
-
* (non-deep,
|
|
11
|
-
* [`===`](https://developer.mozilla.org/
|
|
10
|
+
* Asserts that two objects are deeply equal by checking only their top-level values for strict
|
|
11
|
+
* (non-deep, reference, using
|
|
12
|
+
* [`===`](https://developer.mozilla.org/docs/Web/JavaScript/Equality_comparisons_and_sameness#strict_equality_using))
|
|
12
13
|
* equality.
|
|
13
14
|
*
|
|
14
15
|
* Type guards the first value.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* import {assert} from '@augment-vir/assert';
|
|
21
|
+
*
|
|
22
|
+
* assert.entriesEqual({a: 'a'}, {a: 'a'}); // passes
|
|
23
|
+
*
|
|
24
|
+
* assert.entriesEqual({a: {b: 'b'}}, {a: {b: 'b'}}); // fails
|
|
25
|
+
*
|
|
26
|
+
* const bExample = {b: 'b'};
|
|
27
|
+
* assert.entriesEqual({a: bExample}, {a: bExample}); // passes
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @throws {@link AssertionError} If both inputs are not equal.
|
|
31
|
+
* @see
|
|
32
|
+
* - {@link assert.notEntriesEqual} : the opposite assertion.
|
|
33
|
+
* - {@link assert.jsonEquals} : another deep equality assertion.
|
|
34
|
+
* - {@link assert.deepEquals} : the most thorough (but also slow) deep equality assertion.
|
|
15
35
|
*/
|
|
16
36
|
entriesEqual: typeof entriesEqual;
|
|
17
37
|
/**
|
|
18
|
-
*
|
|
19
|
-
* strict (non-deep,
|
|
20
|
-
* [`===`](https://developer.mozilla.org/
|
|
38
|
+
* Asserts that two objects are _not_ deeply equal by checking only their top-level values for
|
|
39
|
+
* strict (non-deep, reference, using
|
|
40
|
+
* [`===`](https://developer.mozilla.org/docs/Web/JavaScript/Equality_comparisons_and_sameness#strict_equality_using))
|
|
21
41
|
* equality.
|
|
22
42
|
*
|
|
23
43
|
* Performs no type guarding.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
*
|
|
47
|
+
* ```ts
|
|
48
|
+
* import {assert} from '@augment-vir/assert';
|
|
49
|
+
*
|
|
50
|
+
* assert.notEntriesEqual({a: 'a'}, {a: 'a'}); // fails
|
|
51
|
+
*
|
|
52
|
+
* assert.notEntriesEqual({a: {b: 'b'}}, {a: {b: 'b'}}); // passes
|
|
53
|
+
*
|
|
54
|
+
* const bExample = {b: 'b'};
|
|
55
|
+
* assert.notEntriesEqual({a: bExample}, {a: bExample}); // fails
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* @throws {@link AssertionError} If both inputs are equal.
|
|
59
|
+
* @see
|
|
60
|
+
* - {@link assert.entriesEqual} : the opposite assertion.
|
|
61
|
+
* - {@link assert.notJsonEquals} : another not deep equality assertion.
|
|
62
|
+
* - {@link assert.notDeepEquals} : the most thorough (but also slow) not deep equality assertion.
|
|
24
63
|
*/
|
|
25
64
|
notEntriesEqual: typeof notEntriesEqual;
|
|
26
65
|
};
|
|
27
|
-
|
|
66
|
+
check: {
|
|
67
|
+
/**
|
|
68
|
+
* Checks that two objects are deeply equal by checking only their top-level values for
|
|
69
|
+
* strict (non-deep, reference, using
|
|
70
|
+
* [`===`](https://developer.mozilla.org/docs/Web/JavaScript/Equality_comparisons_and_sameness#strict_equality_using))
|
|
71
|
+
* equality.
|
|
72
|
+
*
|
|
73
|
+
* Type guards the first value.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
*
|
|
77
|
+
* ```ts
|
|
78
|
+
* import {check} from '@augment-vir/assert';
|
|
79
|
+
*
|
|
80
|
+
* check.entriesEqual({a: 'a'}, {a: 'a'}); // true
|
|
81
|
+
*
|
|
82
|
+
* check.entriesEqual({a: {b: 'b'}}, {a: {b: 'b'}}); // false
|
|
83
|
+
*
|
|
84
|
+
* const bExample = {b: 'b'};
|
|
85
|
+
* check.entriesEqual({a: bExample}, {a: bExample}); // true
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* @see
|
|
89
|
+
* - {@link check.notEntriesEqual} : the opposite check.
|
|
90
|
+
* - {@link check.jsonEquals} : another deep equality check.
|
|
91
|
+
* - {@link check.deepEquals} : the most thorough (but also slow) deep equality check.
|
|
92
|
+
*/
|
|
28
93
|
entriesEqual: <Actual, Expected extends Actual>(actual: Actual, expected: Expected) => actual is Expected;
|
|
94
|
+
/**
|
|
95
|
+
* Checks that two objects are _not_ deeply equal by checking only their top-level values
|
|
96
|
+
* for strict (non-deep, reference, using
|
|
97
|
+
* [`===`](https://developer.mozilla.org/docs/Web/JavaScript/Equality_comparisons_and_sameness#strict_equality_using))
|
|
98
|
+
* equality.
|
|
99
|
+
*
|
|
100
|
+
* Performs no type guarding.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
*
|
|
104
|
+
* ```ts
|
|
105
|
+
* import {check} from '@augment-vir/assert';
|
|
106
|
+
*
|
|
107
|
+
* check.notEntriesEqual({a: 'a'}, {a: 'a'}); // false
|
|
108
|
+
*
|
|
109
|
+
* check.notEntriesEqual({a: {b: 'b'}}, {a: {b: 'b'}}); // true
|
|
110
|
+
*
|
|
111
|
+
* const bExample = {b: 'b'};
|
|
112
|
+
* check.notEntriesEqual({a: bExample}, {a: bExample}); // false
|
|
113
|
+
* ```
|
|
114
|
+
*
|
|
115
|
+
* @see
|
|
116
|
+
* - {@link check.entriesEqual} : the opposite check.
|
|
117
|
+
* - {@link check.notJsonEquals} : another not deep equality check.
|
|
118
|
+
* - {@link check.notDeepEquals} : the most thorough (but also slow) not deep equality check.
|
|
119
|
+
*/
|
|
120
|
+
notEntriesEqual: typeof autoGuardSymbol;
|
|
29
121
|
};
|
|
30
|
-
|
|
122
|
+
assertWrap: {
|
|
123
|
+
/**
|
|
124
|
+
* Asserts that two objects are deeply equal by checking only their top-level values for
|
|
125
|
+
* strict (non-deep, reference, using
|
|
126
|
+
* [`===`](https://developer.mozilla.org/docs/Web/JavaScript/Equality_comparisons_and_sameness#strict_equality_using))
|
|
127
|
+
* equality and, if so, returns the first object.
|
|
128
|
+
*
|
|
129
|
+
* Type guards the first value.
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
*
|
|
133
|
+
* ```ts
|
|
134
|
+
* import {assertWrap} from '@augment-vir/assert';
|
|
135
|
+
*
|
|
136
|
+
* assertWrap.entriesEqual({a: 'a'}, {a: 'a'}); // returns `{a: 'a'}`
|
|
137
|
+
*
|
|
138
|
+
* assertWrap.entriesEqual({a: {b: 'b'}}, {a: {b: 'b'}}); // throws an error
|
|
139
|
+
*
|
|
140
|
+
* const bExample = {b: 'b'};
|
|
141
|
+
* assertWrap.entriesEqual({a: bExample}, {a: bExample}); // returns `{a: {b: 'b'}}`
|
|
142
|
+
* ```
|
|
143
|
+
*
|
|
144
|
+
* @returns The first input if the assertion passes.
|
|
145
|
+
* @throws {@link AssertionError} If both inputs are not equal.
|
|
146
|
+
* @see
|
|
147
|
+
* - {@link assertWrap.notEntriesEqual} : the opposite assertion.
|
|
148
|
+
* - {@link assertWrap.jsonEquals} : another deep equality assertion.
|
|
149
|
+
* - {@link assertWrap.deepEquals} : the most thorough (but also slow) deep equality assertion.
|
|
150
|
+
*/
|
|
31
151
|
entriesEqual: <Actual, Expected extends Actual>(actual: Actual, expected: Expected, failureMessage?: string | undefined) => NarrowToExpected<Actual, Expected>;
|
|
152
|
+
/**
|
|
153
|
+
* Asserts that two objects are _not_ deeply equal by checking only their top-level values
|
|
154
|
+
* for strict (non-deep, reference, using
|
|
155
|
+
* [`===`](https://developer.mozilla.org/docs/Web/JavaScript/Equality_comparisons_and_sameness#strict_equality_using))
|
|
156
|
+
* equality and, if so, returns the first object.
|
|
157
|
+
*
|
|
158
|
+
* Performs no type guarding.
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
*
|
|
162
|
+
* ```ts
|
|
163
|
+
* import {assertWrap} from '@augment-vir/assert';
|
|
164
|
+
*
|
|
165
|
+
* assertWrap.notEntriesEqual({a: 'a'}, {a: 'a'}); // throws an error
|
|
166
|
+
*
|
|
167
|
+
* assertWrap.notEntriesEqual({a: {b: 'b'}}, {a: {b: 'b'}}); // returns `{a: {b: 'b'}}`
|
|
168
|
+
*
|
|
169
|
+
* const bExample = {b: 'b'};
|
|
170
|
+
* assertWrap.notEntriesEqual({a: bExample}, {a: bExample}); // throws an error
|
|
171
|
+
* ```
|
|
172
|
+
*
|
|
173
|
+
* @returns The first input if the assertion passes.
|
|
174
|
+
* @throws {@link AssertionError} If both inputs are equal.
|
|
175
|
+
* @see
|
|
176
|
+
* - {@link assertWrap.entriesEqual} : the opposite assertion.
|
|
177
|
+
* - {@link assertWrap.notJsonEquals} : another not deep equality assertion.
|
|
178
|
+
* - {@link assertWrap.notDeepEquals} : the most thorough (but also slow) not deep equality assertion.
|
|
179
|
+
*/
|
|
180
|
+
notEntriesEqual: typeof autoGuardSymbol;
|
|
32
181
|
};
|
|
33
|
-
|
|
182
|
+
checkWrap: {
|
|
183
|
+
/**
|
|
184
|
+
* Checks that two objects are deeply equal by checking only their top-level values for
|
|
185
|
+
* strict (non-deep, reference, using
|
|
186
|
+
* [`===`](https://developer.mozilla.org/docs/Web/JavaScript/Equality_comparisons_and_sameness#strict_equality_using))
|
|
187
|
+
* equality. If the check passes the first object is returned. If not, `undefined` is
|
|
188
|
+
* returned.
|
|
189
|
+
*
|
|
190
|
+
* Type guards the first value.
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
*
|
|
194
|
+
* ```ts
|
|
195
|
+
* import {checkWrap} from '@augment-vir/assert';
|
|
196
|
+
*
|
|
197
|
+
* checkWrap.entriesEqual({a: 'a'}, {a: 'a'}); // returns `{a: 'a'}`
|
|
198
|
+
*
|
|
199
|
+
* checkWrap.entriesEqual({a: {b: 'b'}}, {a: {b: 'b'}}); // returns `undefined`
|
|
200
|
+
*
|
|
201
|
+
* const bExample = {b: 'b'};
|
|
202
|
+
* checkWrap.entriesEqual({a: bExample}, {a: bExample}); // returns `{a: {b: 'b'}}`
|
|
203
|
+
* ```
|
|
204
|
+
*
|
|
205
|
+
* @returns The first input if the assertion passes, otherwise `undefined`.
|
|
206
|
+
* @see
|
|
207
|
+
* - {@link checkWrap.notEntriesEqual} : the opposite check.
|
|
208
|
+
* - {@link checkWrap.jsonEquals} : another deep equality check.
|
|
209
|
+
* - {@link checkWrap.deepEquals} : the most thorough (but also slow) deep equality check.
|
|
210
|
+
*/
|
|
34
211
|
entriesEqual: <Actual, Expected extends Actual>(actual: Actual, expected: Expected) => NarrowToExpected<Actual, Expected> | undefined;
|
|
212
|
+
/**
|
|
213
|
+
* Checks that two objects are _not_ deeply equal by checking only their top-level values
|
|
214
|
+
* for strict (non-deep, reference, using
|
|
215
|
+
* [`===`](https://developer.mozilla.org/docs/Web/JavaScript/Equality_comparisons_and_sameness#strict_equality_using))
|
|
216
|
+
* equality. If the check passes the first object is returned. If not, `undefined` is
|
|
217
|
+
* returned.
|
|
218
|
+
*
|
|
219
|
+
* Performs no type guarding.
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
*
|
|
223
|
+
* ```ts
|
|
224
|
+
* import {checkWrap} from '@augment-vir/assert';
|
|
225
|
+
*
|
|
226
|
+
* checkWrap.notEntriesEqual({a: 'a'}, {a: 'a'}); // returns `undefined`
|
|
227
|
+
*
|
|
228
|
+
* checkWrap.notEntriesEqual({a: {b: 'b'}}, {a: {b: 'b'}}); // returns `{a: {b: 'b'}}`
|
|
229
|
+
*
|
|
230
|
+
* const bExample = {b: 'b'};
|
|
231
|
+
* checkWrap.notEntriesEqual({a: bExample}, {a: bExample}); // returns `undefined`
|
|
232
|
+
* ```
|
|
233
|
+
*
|
|
234
|
+
* @returns The first input if the assertion passes, otherwise `undefined`.
|
|
235
|
+
* @see
|
|
236
|
+
* - {@link checkWrap.entriesEqual} : the opposite check.
|
|
237
|
+
* - {@link checkWrap.notJsonEquals} : another not deep equality check.
|
|
238
|
+
* - {@link checkWrap.notDeepEquals} : the most thorough (but also slow) not deep equality check.
|
|
239
|
+
*/
|
|
240
|
+
notEntriesEqual: typeof autoGuardSymbol;
|
|
35
241
|
};
|
|
36
|
-
|
|
242
|
+
waitUntil: {
|
|
243
|
+
/**
|
|
244
|
+
* Repeatedly calls a callback until its output is deeply equal to the first input by
|
|
245
|
+
* checking only their top-level values for strict (non-deep, reference, using
|
|
246
|
+
* [`===`](https://developer.mozilla.org/docs/Web/JavaScript/Equality_comparisons_and_sameness#strict_equality_using))
|
|
247
|
+
* equality. Once the callback output passes, it is returned. If the attempts time out, an
|
|
248
|
+
* error is thrown.
|
|
249
|
+
*
|
|
250
|
+
* Type guards the first value.
|
|
251
|
+
*
|
|
252
|
+
* @example
|
|
253
|
+
*
|
|
254
|
+
* ```ts
|
|
255
|
+
* import {waitUntil} from '@augment-vir/assert';
|
|
256
|
+
*
|
|
257
|
+
* await waitUntil.entriesEqual({a: 'a'}, () => {
|
|
258
|
+
* return {a: 'a'};
|
|
259
|
+
* }); // returns `{a: 'a'}`
|
|
260
|
+
*
|
|
261
|
+
* await waitUntil.entriesEqual({a: {b: 'b'}}, () => {
|
|
262
|
+
* return {a: {b: 'b'}};
|
|
263
|
+
* }); // throws an error
|
|
264
|
+
*
|
|
265
|
+
* const bExample = {b: 'b'};
|
|
266
|
+
* await waitUntil.entriesEqual({a: bExample}, () => {
|
|
267
|
+
* return {a: bExample};
|
|
268
|
+
* }); // returns `{a: {b: 'b'}}`
|
|
269
|
+
* ```
|
|
270
|
+
*
|
|
271
|
+
* @throws {@link AssertionError} On timeout.
|
|
272
|
+
* @see
|
|
273
|
+
* - {@link waitUntil.notEntriesEqual} : the opposite assertion.
|
|
274
|
+
* - {@link waitUntil.jsonEquals} : another deep equality assertion.
|
|
275
|
+
* - {@link waitUntil.deepEquals} : the most thorough (but also slow) deep equality assertion.
|
|
276
|
+
*/
|
|
37
277
|
entriesEqual: <Actual, Expected extends Actual>(expected: Expected, callback: () => MaybePromise<Actual>, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined) => Promise<NarrowToExpected<Actual, Expected>>;
|
|
278
|
+
/**
|
|
279
|
+
* Repeatedly calls a callback until its output is _not_ deeply equal to the first input by
|
|
280
|
+
* checking only their top-level values for strict (non-deep, reference, using
|
|
281
|
+
* [`===`](https://developer.mozilla.org/docs/Web/JavaScript/Equality_comparisons_and_sameness#strict_equality_using))
|
|
282
|
+
* equality. Once the callback output passes, it is returned. If the attempts time out, an
|
|
283
|
+
* error is thrown.
|
|
284
|
+
*
|
|
285
|
+
* Performs no type guarding.
|
|
286
|
+
*
|
|
287
|
+
* @example
|
|
288
|
+
*
|
|
289
|
+
* ```ts
|
|
290
|
+
* import {waitUntil} from '@augment-vir/assert';
|
|
291
|
+
*
|
|
292
|
+
* await waitUntil.notEntriesEqual({a: 'a'}, () => {
|
|
293
|
+
* return {a: 'a'};
|
|
294
|
+
* }); // throws an error
|
|
295
|
+
*
|
|
296
|
+
* await waitUntil.notEntriesEqual({a: {b: 'b'}}, () => {
|
|
297
|
+
* return {a: {b: 'b'}};
|
|
298
|
+
* }); // returns `{a: {b: 'b'}}`
|
|
299
|
+
*
|
|
300
|
+
* const bExample = {b: 'b'};
|
|
301
|
+
* await waitUntil.notEntriesEqual({a: bExample}, () => {
|
|
302
|
+
* return {a: bExample};
|
|
303
|
+
* }); // throws an error
|
|
304
|
+
* ```
|
|
305
|
+
*
|
|
306
|
+
* @returns The callback output once it passes.
|
|
307
|
+
* @throws {@link AssertionError} If both inputs are equal.
|
|
308
|
+
* @see
|
|
309
|
+
* - {@link waitUntil.entriesEqual} : the opposite assertion.
|
|
310
|
+
* - {@link waitUntil.notJsonEquals} : another not deep equality assertion.
|
|
311
|
+
* - {@link waitUntil.notDeepEquals} : the most thorough (but also slow) not deep equality assertion.
|
|
312
|
+
*/
|
|
313
|
+
notEntriesEqual: typeof autoGuardSymbol;
|
|
38
314
|
};
|
|
39
315
|
};
|
|
40
316
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { stringify } from '@augment-vir/core';
|
|
2
2
|
import { AssertionError } from '../../augments/assertion.error.js';
|
|
3
|
-
import { autoGuard } from '../../guard-types/guard-override.js';
|
|
3
|
+
import { autoGuard, autoGuardSymbol } from '../../guard-types/guard-override.js';
|
|
4
4
|
import { strictEquals } from './simple-equality.js';
|
|
5
5
|
function entriesEqual(actual, expected, failureMessage) {
|
|
6
6
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
@@ -40,17 +40,254 @@ const assertions = {
|
|
|
40
40
|
notEntriesEqual,
|
|
41
41
|
};
|
|
42
42
|
export const entryEqualityGuards = {
|
|
43
|
-
assertions,
|
|
44
|
-
|
|
43
|
+
assert: assertions,
|
|
44
|
+
check: {
|
|
45
|
+
/**
|
|
46
|
+
* Checks that two objects are deeply equal by checking only their top-level values for
|
|
47
|
+
* strict (non-deep, reference, using
|
|
48
|
+
* [`===`](https://developer.mozilla.org/docs/Web/JavaScript/Equality_comparisons_and_sameness#strict_equality_using))
|
|
49
|
+
* equality.
|
|
50
|
+
*
|
|
51
|
+
* Type guards the first value.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
*
|
|
55
|
+
* ```ts
|
|
56
|
+
* import {check} from '@augment-vir/assert';
|
|
57
|
+
*
|
|
58
|
+
* check.entriesEqual({a: 'a'}, {a: 'a'}); // true
|
|
59
|
+
*
|
|
60
|
+
* check.entriesEqual({a: {b: 'b'}}, {a: {b: 'b'}}); // false
|
|
61
|
+
*
|
|
62
|
+
* const bExample = {b: 'b'};
|
|
63
|
+
* check.entriesEqual({a: bExample}, {a: bExample}); // true
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* @see
|
|
67
|
+
* - {@link check.notEntriesEqual} : the opposite check.
|
|
68
|
+
* - {@link check.jsonEquals} : another deep equality check.
|
|
69
|
+
* - {@link check.deepEquals} : the most thorough (but also slow) deep equality check.
|
|
70
|
+
*/
|
|
45
71
|
entriesEqual: autoGuard(),
|
|
72
|
+
/**
|
|
73
|
+
* Checks that two objects are _not_ deeply equal by checking only their top-level values
|
|
74
|
+
* for strict (non-deep, reference, using
|
|
75
|
+
* [`===`](https://developer.mozilla.org/docs/Web/JavaScript/Equality_comparisons_and_sameness#strict_equality_using))
|
|
76
|
+
* equality.
|
|
77
|
+
*
|
|
78
|
+
* Performs no type guarding.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
*
|
|
82
|
+
* ```ts
|
|
83
|
+
* import {check} from '@augment-vir/assert';
|
|
84
|
+
*
|
|
85
|
+
* check.notEntriesEqual({a: 'a'}, {a: 'a'}); // false
|
|
86
|
+
*
|
|
87
|
+
* check.notEntriesEqual({a: {b: 'b'}}, {a: {b: 'b'}}); // true
|
|
88
|
+
*
|
|
89
|
+
* const bExample = {b: 'b'};
|
|
90
|
+
* check.notEntriesEqual({a: bExample}, {a: bExample}); // false
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
* @see
|
|
94
|
+
* - {@link check.entriesEqual} : the opposite check.
|
|
95
|
+
* - {@link check.notJsonEquals} : another not deep equality check.
|
|
96
|
+
* - {@link check.notDeepEquals} : the most thorough (but also slow) not deep equality check.
|
|
97
|
+
*/
|
|
98
|
+
notEntriesEqual: autoGuardSymbol,
|
|
46
99
|
},
|
|
47
|
-
|
|
100
|
+
assertWrap: {
|
|
101
|
+
/**
|
|
102
|
+
* Asserts that two objects are deeply equal by checking only their top-level values for
|
|
103
|
+
* strict (non-deep, reference, using
|
|
104
|
+
* [`===`](https://developer.mozilla.org/docs/Web/JavaScript/Equality_comparisons_and_sameness#strict_equality_using))
|
|
105
|
+
* equality and, if so, returns the first object.
|
|
106
|
+
*
|
|
107
|
+
* Type guards the first value.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
*
|
|
111
|
+
* ```ts
|
|
112
|
+
* import {assertWrap} from '@augment-vir/assert';
|
|
113
|
+
*
|
|
114
|
+
* assertWrap.entriesEqual({a: 'a'}, {a: 'a'}); // returns `{a: 'a'}`
|
|
115
|
+
*
|
|
116
|
+
* assertWrap.entriesEqual({a: {b: 'b'}}, {a: {b: 'b'}}); // throws an error
|
|
117
|
+
*
|
|
118
|
+
* const bExample = {b: 'b'};
|
|
119
|
+
* assertWrap.entriesEqual({a: bExample}, {a: bExample}); // returns `{a: {b: 'b'}}`
|
|
120
|
+
* ```
|
|
121
|
+
*
|
|
122
|
+
* @returns The first input if the assertion passes.
|
|
123
|
+
* @throws {@link AssertionError} If both inputs are not equal.
|
|
124
|
+
* @see
|
|
125
|
+
* - {@link assertWrap.notEntriesEqual} : the opposite assertion.
|
|
126
|
+
* - {@link assertWrap.jsonEquals} : another deep equality assertion.
|
|
127
|
+
* - {@link assertWrap.deepEquals} : the most thorough (but also slow) deep equality assertion.
|
|
128
|
+
*/
|
|
48
129
|
entriesEqual: autoGuard(),
|
|
130
|
+
/**
|
|
131
|
+
* Asserts that two objects are _not_ deeply equal by checking only their top-level values
|
|
132
|
+
* for strict (non-deep, reference, using
|
|
133
|
+
* [`===`](https://developer.mozilla.org/docs/Web/JavaScript/Equality_comparisons_and_sameness#strict_equality_using))
|
|
134
|
+
* equality and, if so, returns the first object.
|
|
135
|
+
*
|
|
136
|
+
* Performs no type guarding.
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
*
|
|
140
|
+
* ```ts
|
|
141
|
+
* import {assertWrap} from '@augment-vir/assert';
|
|
142
|
+
*
|
|
143
|
+
* assertWrap.notEntriesEqual({a: 'a'}, {a: 'a'}); // throws an error
|
|
144
|
+
*
|
|
145
|
+
* assertWrap.notEntriesEqual({a: {b: 'b'}}, {a: {b: 'b'}}); // returns `{a: {b: 'b'}}`
|
|
146
|
+
*
|
|
147
|
+
* const bExample = {b: 'b'};
|
|
148
|
+
* assertWrap.notEntriesEqual({a: bExample}, {a: bExample}); // throws an error
|
|
149
|
+
* ```
|
|
150
|
+
*
|
|
151
|
+
* @returns The first input if the assertion passes.
|
|
152
|
+
* @throws {@link AssertionError} If both inputs are equal.
|
|
153
|
+
* @see
|
|
154
|
+
* - {@link assertWrap.entriesEqual} : the opposite assertion.
|
|
155
|
+
* - {@link assertWrap.notJsonEquals} : another not deep equality assertion.
|
|
156
|
+
* - {@link assertWrap.notDeepEquals} : the most thorough (but also slow) not deep equality assertion.
|
|
157
|
+
*/
|
|
158
|
+
notEntriesEqual: autoGuardSymbol,
|
|
49
159
|
},
|
|
50
|
-
|
|
160
|
+
checkWrap: {
|
|
161
|
+
/**
|
|
162
|
+
* Checks that two objects are deeply equal by checking only their top-level values for
|
|
163
|
+
* strict (non-deep, reference, using
|
|
164
|
+
* [`===`](https://developer.mozilla.org/docs/Web/JavaScript/Equality_comparisons_and_sameness#strict_equality_using))
|
|
165
|
+
* equality. If the check passes the first object is returned. If not, `undefined` is
|
|
166
|
+
* returned.
|
|
167
|
+
*
|
|
168
|
+
* Type guards the first value.
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
*
|
|
172
|
+
* ```ts
|
|
173
|
+
* import {checkWrap} from '@augment-vir/assert';
|
|
174
|
+
*
|
|
175
|
+
* checkWrap.entriesEqual({a: 'a'}, {a: 'a'}); // returns `{a: 'a'}`
|
|
176
|
+
*
|
|
177
|
+
* checkWrap.entriesEqual({a: {b: 'b'}}, {a: {b: 'b'}}); // returns `undefined`
|
|
178
|
+
*
|
|
179
|
+
* const bExample = {b: 'b'};
|
|
180
|
+
* checkWrap.entriesEqual({a: bExample}, {a: bExample}); // returns `{a: {b: 'b'}}`
|
|
181
|
+
* ```
|
|
182
|
+
*
|
|
183
|
+
* @returns The first input if the assertion passes, otherwise `undefined`.
|
|
184
|
+
* @see
|
|
185
|
+
* - {@link checkWrap.notEntriesEqual} : the opposite check.
|
|
186
|
+
* - {@link checkWrap.jsonEquals} : another deep equality check.
|
|
187
|
+
* - {@link checkWrap.deepEquals} : the most thorough (but also slow) deep equality check.
|
|
188
|
+
*/
|
|
51
189
|
entriesEqual: autoGuard(),
|
|
190
|
+
/**
|
|
191
|
+
* Checks that two objects are _not_ deeply equal by checking only their top-level values
|
|
192
|
+
* for strict (non-deep, reference, using
|
|
193
|
+
* [`===`](https://developer.mozilla.org/docs/Web/JavaScript/Equality_comparisons_and_sameness#strict_equality_using))
|
|
194
|
+
* equality. If the check passes the first object is returned. If not, `undefined` is
|
|
195
|
+
* returned.
|
|
196
|
+
*
|
|
197
|
+
* Performs no type guarding.
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
*
|
|
201
|
+
* ```ts
|
|
202
|
+
* import {checkWrap} from '@augment-vir/assert';
|
|
203
|
+
*
|
|
204
|
+
* checkWrap.notEntriesEqual({a: 'a'}, {a: 'a'}); // returns `undefined`
|
|
205
|
+
*
|
|
206
|
+
* checkWrap.notEntriesEqual({a: {b: 'b'}}, {a: {b: 'b'}}); // returns `{a: {b: 'b'}}`
|
|
207
|
+
*
|
|
208
|
+
* const bExample = {b: 'b'};
|
|
209
|
+
* checkWrap.notEntriesEqual({a: bExample}, {a: bExample}); // returns `undefined`
|
|
210
|
+
* ```
|
|
211
|
+
*
|
|
212
|
+
* @returns The first input if the assertion passes, otherwise `undefined`.
|
|
213
|
+
* @see
|
|
214
|
+
* - {@link checkWrap.entriesEqual} : the opposite check.
|
|
215
|
+
* - {@link checkWrap.notJsonEquals} : another not deep equality check.
|
|
216
|
+
* - {@link checkWrap.notDeepEquals} : the most thorough (but also slow) not deep equality check.
|
|
217
|
+
*/
|
|
218
|
+
notEntriesEqual: autoGuardSymbol,
|
|
52
219
|
},
|
|
53
|
-
|
|
220
|
+
waitUntil: {
|
|
221
|
+
/**
|
|
222
|
+
* Repeatedly calls a callback until its output is deeply equal to the first input by
|
|
223
|
+
* checking only their top-level values for strict (non-deep, reference, using
|
|
224
|
+
* [`===`](https://developer.mozilla.org/docs/Web/JavaScript/Equality_comparisons_and_sameness#strict_equality_using))
|
|
225
|
+
* equality. Once the callback output passes, it is returned. If the attempts time out, an
|
|
226
|
+
* error is thrown.
|
|
227
|
+
*
|
|
228
|
+
* Type guards the first value.
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
*
|
|
232
|
+
* ```ts
|
|
233
|
+
* import {waitUntil} from '@augment-vir/assert';
|
|
234
|
+
*
|
|
235
|
+
* await waitUntil.entriesEqual({a: 'a'}, () => {
|
|
236
|
+
* return {a: 'a'};
|
|
237
|
+
* }); // returns `{a: 'a'}`
|
|
238
|
+
*
|
|
239
|
+
* await waitUntil.entriesEqual({a: {b: 'b'}}, () => {
|
|
240
|
+
* return {a: {b: 'b'}};
|
|
241
|
+
* }); // throws an error
|
|
242
|
+
*
|
|
243
|
+
* const bExample = {b: 'b'};
|
|
244
|
+
* await waitUntil.entriesEqual({a: bExample}, () => {
|
|
245
|
+
* return {a: bExample};
|
|
246
|
+
* }); // returns `{a: {b: 'b'}}`
|
|
247
|
+
* ```
|
|
248
|
+
*
|
|
249
|
+
* @throws {@link AssertionError} On timeout.
|
|
250
|
+
* @see
|
|
251
|
+
* - {@link waitUntil.notEntriesEqual} : the opposite assertion.
|
|
252
|
+
* - {@link waitUntil.jsonEquals} : another deep equality assertion.
|
|
253
|
+
* - {@link waitUntil.deepEquals} : the most thorough (but also slow) deep equality assertion.
|
|
254
|
+
*/
|
|
54
255
|
entriesEqual: autoGuard(),
|
|
256
|
+
/**
|
|
257
|
+
* Repeatedly calls a callback until its output is _not_ deeply equal to the first input by
|
|
258
|
+
* checking only their top-level values for strict (non-deep, reference, using
|
|
259
|
+
* [`===`](https://developer.mozilla.org/docs/Web/JavaScript/Equality_comparisons_and_sameness#strict_equality_using))
|
|
260
|
+
* equality. Once the callback output passes, it is returned. If the attempts time out, an
|
|
261
|
+
* error is thrown.
|
|
262
|
+
*
|
|
263
|
+
* Performs no type guarding.
|
|
264
|
+
*
|
|
265
|
+
* @example
|
|
266
|
+
*
|
|
267
|
+
* ```ts
|
|
268
|
+
* import {waitUntil} from '@augment-vir/assert';
|
|
269
|
+
*
|
|
270
|
+
* await waitUntil.notEntriesEqual({a: 'a'}, () => {
|
|
271
|
+
* return {a: 'a'};
|
|
272
|
+
* }); // throws an error
|
|
273
|
+
*
|
|
274
|
+
* await waitUntil.notEntriesEqual({a: {b: 'b'}}, () => {
|
|
275
|
+
* return {a: {b: 'b'}};
|
|
276
|
+
* }); // returns `{a: {b: 'b'}}`
|
|
277
|
+
*
|
|
278
|
+
* const bExample = {b: 'b'};
|
|
279
|
+
* await waitUntil.notEntriesEqual({a: bExample}, () => {
|
|
280
|
+
* return {a: bExample};
|
|
281
|
+
* }); // throws an error
|
|
282
|
+
* ```
|
|
283
|
+
*
|
|
284
|
+
* @returns The callback output once it passes.
|
|
285
|
+
* @throws {@link AssertionError} If both inputs are equal.
|
|
286
|
+
* @see
|
|
287
|
+
* - {@link waitUntil.entriesEqual} : the opposite assertion.
|
|
288
|
+
* - {@link waitUntil.notJsonEquals} : another not deep equality assertion.
|
|
289
|
+
* - {@link waitUntil.notDeepEquals} : the most thorough (but also slow) not deep equality assertion.
|
|
290
|
+
*/
|
|
291
|
+
notEntriesEqual: autoGuardSymbol,
|
|
55
292
|
},
|
|
56
293
|
};
|