@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,42 +1,271 @@
|
|
|
1
1
|
import { MaybePromise, NarrowToExpected } from '@augment-vir/core';
|
|
2
|
+
import { autoGuardSymbol } from '../../guard-types/guard-override.js';
|
|
2
3
|
import { WaitUntilOptions } from '../../guard-types/wait-until-function.js';
|
|
3
|
-
/**
|
|
4
|
-
* Check if the inputs are equal via `JSON.stringify` (property order on objects does not matter).
|
|
5
|
-
*
|
|
6
|
-
* @throws `JsonStringifyError` if the inputs fail when passed to `JSON.stringify`.
|
|
7
|
-
*/
|
|
8
4
|
declare function jsonEquals<const Actual, const Expected extends Actual>(actual: Actual, expected: Expected, failureMessage?: string | undefined): asserts actual is Expected;
|
|
9
5
|
declare function notJsonEquals(actual: unknown, expected: unknown, failureMessage?: string | undefined): void;
|
|
10
6
|
export declare const jsonEqualityGuards: {
|
|
11
|
-
|
|
7
|
+
assert: {
|
|
12
8
|
/**
|
|
13
|
-
*
|
|
14
|
-
* make any sense if the
|
|
9
|
+
* Asserts that two values are deeply equal when stringified into JSON. This will fail or may
|
|
10
|
+
* not make any sense if the values are not valid JSON. This internally sorts all given object
|
|
15
11
|
* keys so it is insensitive to object key order.
|
|
16
12
|
*
|
|
17
13
|
* Type guards the first value.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* import {assert} from '@augment-vir/assert';
|
|
19
|
+
*
|
|
20
|
+
* assert.jsonEquals({a: 'a'}, {a: 'a'}); // passes
|
|
21
|
+
*
|
|
22
|
+
* assert.jsonEquals({a: {b: 'b'}}, {a: {b: 'c'}}); // fails
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @throws {@link AssertionError} If both inputs are not equal.
|
|
26
|
+
* @see
|
|
27
|
+
* - {@link assert.notJsonEquals} : the opposite assertion.
|
|
28
|
+
* - {@link assert.entriesEqual} : another deep equality assertion.
|
|
29
|
+
* - {@link assert.deepEquals} : the most thorough (but also slow) deep equality assertion.
|
|
18
30
|
*/
|
|
19
31
|
jsonEquals: typeof jsonEquals;
|
|
20
32
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
33
|
+
* Asserts that two values are _not_ deeply equal when stringified into JSON. This may not make
|
|
34
|
+
* any sense if the values are not valid JSON. This internally sorts all given object keys so it
|
|
35
|
+
* is insensitive to object key order.
|
|
24
36
|
*
|
|
25
37
|
* Performs no type guarding.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
*
|
|
41
|
+
* ```ts
|
|
42
|
+
* import {assert} from '@augment-vir/assert';
|
|
43
|
+
*
|
|
44
|
+
* assert.notJsonEquals({a: 'a'}, {a: 'a'}); // fails
|
|
45
|
+
*
|
|
46
|
+
* assert.notJsonEquals({a: {b: 'b'}}, {a: {b: 'c'}}); // passes
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @throws {@link AssertionError} If both inputs are not equal.
|
|
50
|
+
* @see
|
|
51
|
+
* - {@link assert.jsonEquals} : the opposite assertion.
|
|
52
|
+
* - {@link assert.entriesEqual} : another deep equality assertion.
|
|
53
|
+
* - {@link assert.deepEquals} : the most thorough (but also slow) deep equality assertion.
|
|
26
54
|
*/
|
|
27
55
|
notJsonEquals: typeof notJsonEquals;
|
|
28
56
|
};
|
|
29
|
-
|
|
57
|
+
check: {
|
|
58
|
+
/**
|
|
59
|
+
* Checks that two values are deeply equal when stringified into JSON. This will fail or may
|
|
60
|
+
* not make any sense if the values are not valid JSON. This internally sorts all given
|
|
61
|
+
* object keys so it is insensitive to object key order.
|
|
62
|
+
*
|
|
63
|
+
* Type guards the first value.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
*
|
|
67
|
+
* ```ts
|
|
68
|
+
* import {check} from '@augment-vir/assert';
|
|
69
|
+
*
|
|
70
|
+
* check.jsonEquals({a: 'a'}, {a: 'a'}); // true
|
|
71
|
+
*
|
|
72
|
+
* check.jsonEquals({a: {b: 'b'}}, {a: {b: 'c'}}); // false
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* @see
|
|
76
|
+
* - {@link check.notJsonEquals} : the opposite check.
|
|
77
|
+
* - {@link check.entriesEqual} : another deep equality check.
|
|
78
|
+
* - {@link check.deepEquals} : the most thorough (but also slow) deep equality check.
|
|
79
|
+
*/
|
|
30
80
|
jsonEquals: <Actual, Expected extends Actual>(actual: Actual, expected: Expected) => actual is Expected;
|
|
81
|
+
/**
|
|
82
|
+
* Checks that two values are _not_ deeply equal when stringified into JSON. This may not
|
|
83
|
+
* make any sense if the values are not valid JSON. This internally sorts all given object
|
|
84
|
+
* keys so it is insensitive to object key order.
|
|
85
|
+
*
|
|
86
|
+
* Performs no type guarding.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
*
|
|
90
|
+
* ```ts
|
|
91
|
+
* import {check} from '@augment-vir/assert';
|
|
92
|
+
*
|
|
93
|
+
* check.notJsonEquals({a: 'a'}, {a: 'a'}); // false
|
|
94
|
+
*
|
|
95
|
+
* check.notJsonEquals({a: {b: 'b'}}, {a: {b: 'c'}}); // true
|
|
96
|
+
* ```
|
|
97
|
+
*
|
|
98
|
+
* @see
|
|
99
|
+
* - {@link check.jsonEquals} : the opposite check.
|
|
100
|
+
* - {@link check.entriesEqual} : another deep equality check.
|
|
101
|
+
* - {@link check.deepEquals} : the most thorough (but also slow) deep equality check.
|
|
102
|
+
*/
|
|
103
|
+
notJsonEquals: typeof autoGuardSymbol;
|
|
31
104
|
};
|
|
32
|
-
|
|
105
|
+
assertWrap: {
|
|
106
|
+
/**
|
|
107
|
+
* Asserts that two values are deeply equal when stringified into JSON. This will fail or
|
|
108
|
+
* may not make any sense if the values are not valid JSON. This internally sorts all given
|
|
109
|
+
* object keys so it is insensitive to object key order. Returns the first value if the
|
|
110
|
+
* assertion passes.
|
|
111
|
+
*
|
|
112
|
+
* Type guards the first value.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
*
|
|
116
|
+
* ```ts
|
|
117
|
+
* import {assertWrap} from '@augment-vir/assert';
|
|
118
|
+
*
|
|
119
|
+
* assertWrap.jsonEquals({a: 'a'}, {a: 'a'}); // returns `{a: 'a'}`
|
|
120
|
+
*
|
|
121
|
+
* assertWrap.jsonEquals({a: {b: 'b'}}, {a: {b: 'c'}}); // throws an error
|
|
122
|
+
* ```
|
|
123
|
+
*
|
|
124
|
+
* @throws {@link AssertionError} If both inputs are not equal.
|
|
125
|
+
* @see
|
|
126
|
+
* - {@link assertWrap.notJsonEquals} : the opposite assertion.
|
|
127
|
+
* - {@link assertWrap.entriesEqual} : another deep equality assertion.
|
|
128
|
+
* - {@link assertWrap.deepEquals} : the most thorough (but also slow) deep equality assertion.
|
|
129
|
+
*/
|
|
33
130
|
jsonEquals: <Actual, Expected extends Actual>(actual: Actual, expected: Expected, failureMessage?: string | undefined) => NarrowToExpected<Actual, Expected>;
|
|
131
|
+
/**
|
|
132
|
+
* Asserts that two values are _not_ deeply equal when stringified into JSON. This may not
|
|
133
|
+
* make any sense if the values are not valid JSON. This internally sorts all given object
|
|
134
|
+
* keys so it is insensitive to object key order. Returns the first value if the assertion
|
|
135
|
+
* passes.
|
|
136
|
+
*
|
|
137
|
+
* Performs no type guarding.
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
*
|
|
141
|
+
* ```ts
|
|
142
|
+
* import {assertWrap} from '@augment-vir/assert';
|
|
143
|
+
*
|
|
144
|
+
* assertWrap.notJsonEquals({a: 'a'}, {a: 'a'}); // throws an error
|
|
145
|
+
*
|
|
146
|
+
* assertWrap.notJsonEquals({a: {b: 'b'}}, {a: {b: 'c'}}); // returns `{a: {b: 'b'}}`
|
|
147
|
+
* ```
|
|
148
|
+
*
|
|
149
|
+
* @throws {@link AssertionError} If both inputs are not equal.
|
|
150
|
+
* @see
|
|
151
|
+
* - {@link assertWrap.jsonEquals} : the opposite assertion.
|
|
152
|
+
* - {@link assertWrap.entriesEqual} : another deep equality assertion.
|
|
153
|
+
* - {@link assertWrap.deepEquals} : the most thorough (but also slow) deep equality assertion.
|
|
154
|
+
*/
|
|
155
|
+
notJsonEquals: typeof autoGuardSymbol;
|
|
34
156
|
};
|
|
35
|
-
|
|
157
|
+
checkWrap: {
|
|
158
|
+
/**
|
|
159
|
+
* Checks that two values are deeply equal when stringified into JSON. This will fail or may
|
|
160
|
+
* not make any sense if the values are not valid JSON. This internally sorts all given
|
|
161
|
+
* object keys so it is insensitive to object key order. Returns the first value if the
|
|
162
|
+
* check passes.
|
|
163
|
+
*
|
|
164
|
+
* Type guards the first value.
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
*
|
|
168
|
+
* ```ts
|
|
169
|
+
* import {checkWrap} from '@augment-vir/assert';
|
|
170
|
+
*
|
|
171
|
+
* checkWrap.jsonEquals({a: 'a'}, {a: 'a'}); // returns `{a: 'a'}`
|
|
172
|
+
*
|
|
173
|
+
* checkWrap.jsonEquals({a: {b: 'b'}}, {a: {b: 'c'}}); // returns `undefined`
|
|
174
|
+
* ```
|
|
175
|
+
*
|
|
176
|
+
* @see
|
|
177
|
+
* - {@link checkWrap.notJsonEquals} : the opposite check.
|
|
178
|
+
* - {@link checkWrap.entriesEqual} : another deep equality check.
|
|
179
|
+
* - {@link checkWrap.deepEquals} : the most thorough (but also slow) deep equality check.
|
|
180
|
+
*/
|
|
36
181
|
jsonEquals: <Actual, Expected extends Actual>(actual: Actual, expected: Expected) => NarrowToExpected<Actual, Expected> | undefined;
|
|
182
|
+
/**
|
|
183
|
+
* Checks that two values are _not_ deeply equal when stringified into JSON. This may not
|
|
184
|
+
* make any sense if the values are not valid JSON. This internally sorts all given object
|
|
185
|
+
* keys so it is insensitive to object key order. Returns the first value if the check
|
|
186
|
+
* passes.
|
|
187
|
+
*
|
|
188
|
+
* Performs no type guarding.
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
*
|
|
192
|
+
* ```ts
|
|
193
|
+
* import {checkWrap} from '@augment-vir/assert';
|
|
194
|
+
*
|
|
195
|
+
* checkWrap.notJsonEquals({a: 'a'}, {a: 'a'}); // false
|
|
196
|
+
*
|
|
197
|
+
* checkWrap.notJsonEquals({a: {b: 'b'}}, {a: {b: 'c'}}); // true
|
|
198
|
+
* ```
|
|
199
|
+
*
|
|
200
|
+
* @see
|
|
201
|
+
* - {@link checkWrap.jsonEquals} : the opposite check.
|
|
202
|
+
* - {@link checkWrap.entriesEqual} : another deep equality check.
|
|
203
|
+
* - {@link checkWrap.deepEquals} : the most thorough (but also slow) deep equality check.
|
|
204
|
+
*/
|
|
205
|
+
notJsonEquals: typeof autoGuardSymbol;
|
|
37
206
|
};
|
|
38
|
-
|
|
207
|
+
waitUntil: {
|
|
208
|
+
/**
|
|
209
|
+
* Repeatedly calls a callback until its output is deeply equal to the first input when
|
|
210
|
+
* stringified into JSON. This may not make any sense if the values are not valid JSON. This
|
|
211
|
+
* internally sorts all given object keys so it is insensitive to object key order. Once the
|
|
212
|
+
* callback output passes, it is returned. If the attempts time out, an error is thrown.
|
|
213
|
+
*
|
|
214
|
+
* Type guards the first value.
|
|
215
|
+
*
|
|
216
|
+
* @example
|
|
217
|
+
*
|
|
218
|
+
* ```ts
|
|
219
|
+
* import {waitUntil} from '@augment-vir/assert';
|
|
220
|
+
*
|
|
221
|
+
* await waitUntil.jsonEquals({a: 'a'}, () => {
|
|
222
|
+
* return {a: 'a'};
|
|
223
|
+
* }); // returns `{a: 'a'}`
|
|
224
|
+
*
|
|
225
|
+
* await waitUntil.jsonEquals({a: {b: 'c'}}, () => {
|
|
226
|
+
* return {a: {b: 'b'}};
|
|
227
|
+
* }); // throws an error
|
|
228
|
+
* ```
|
|
229
|
+
*
|
|
230
|
+
* @returns The callback output once it passes.
|
|
231
|
+
* @throws {@link AssertionError} On timeout.
|
|
232
|
+
* @see
|
|
233
|
+
* - {@link waitUntil.notJsonEquals} : the opposite assertion.
|
|
234
|
+
* - {@link waitUntil.entriesEqual} : another deep equality assertion.
|
|
235
|
+
* - {@link waitUntil.deepEquals} : the most thorough (but also slow) deep equality assertion.
|
|
236
|
+
*/
|
|
39
237
|
jsonEquals: <Actual, Expected extends Actual>(expected: Expected, callback: () => MaybePromise<Actual>, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined) => Promise<NarrowToExpected<Actual, Expected>>;
|
|
238
|
+
/**
|
|
239
|
+
* Repeatedly calls a callback until its output is _not_ deeply equal to the first input
|
|
240
|
+
* when stringified into JSON. This may not make any sense if the values are not valid JSON.
|
|
241
|
+
* This internally sorts all given object keys so it is insensitive to object key order.
|
|
242
|
+
* Once the callback output passes, it is returned. If the attempts time out, an error is
|
|
243
|
+
* thrown.
|
|
244
|
+
*
|
|
245
|
+
* Performs no type guarding.
|
|
246
|
+
*
|
|
247
|
+
* @example
|
|
248
|
+
*
|
|
249
|
+
* ```ts
|
|
250
|
+
* import {waitUntil} from '@augment-vir/assert';
|
|
251
|
+
*
|
|
252
|
+
* await waitUntil.notJsonEquals({a: 'a'}, () => {
|
|
253
|
+
* return {a: 'a'};
|
|
254
|
+
* }); // throws an error
|
|
255
|
+
*
|
|
256
|
+
* await waitUntil.notJsonEquals({a: {b: 'c'}}, () => {
|
|
257
|
+
* return {a: {b: 'b'}};
|
|
258
|
+
* }); // returns `{a: {b: 'b'}}`
|
|
259
|
+
* ```
|
|
260
|
+
*
|
|
261
|
+
* @returns The callback output once it passes.
|
|
262
|
+
* @throws {@link AssertionError} On timeout.
|
|
263
|
+
* @see
|
|
264
|
+
* - {@link waitUntil.jsonEquals} : the opposite assertion.
|
|
265
|
+
* - {@link waitUntil.entriesEqual} : another not deep equality assertion.
|
|
266
|
+
* - {@link waitUntil.deepEquals} : the most thorough (but also slow) not deep equality assertion.
|
|
267
|
+
*/
|
|
268
|
+
notJsonEquals: typeof autoGuardSymbol;
|
|
40
269
|
};
|
|
41
270
|
};
|
|
42
271
|
export {};
|
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
import { extractErrorMessage } 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
|
function baseJsonEquals(a, b) {
|
|
5
5
|
return JSON.stringify(a) === JSON.stringify(b);
|
|
6
6
|
}
|
|
7
|
-
/**
|
|
8
|
-
* Check if the inputs are equal via `JSON.stringify` (property order on objects does not matter).
|
|
9
|
-
*
|
|
10
|
-
* @throws `JsonStringifyError` if the inputs fail when passed to `JSON.stringify`.
|
|
11
|
-
*/
|
|
12
7
|
function jsonEquals(actual, expected, failureMessage) {
|
|
13
8
|
try {
|
|
14
9
|
recursiveJsonEquals(actual, expected);
|
|
@@ -59,17 +54,218 @@ const assertions = {
|
|
|
59
54
|
notJsonEquals,
|
|
60
55
|
};
|
|
61
56
|
export const jsonEqualityGuards = {
|
|
62
|
-
assertions,
|
|
63
|
-
|
|
57
|
+
assert: assertions,
|
|
58
|
+
check: {
|
|
59
|
+
/**
|
|
60
|
+
* Checks that two values are deeply equal when stringified into JSON. This will fail or may
|
|
61
|
+
* not make any sense if the values are not valid JSON. This internally sorts all given
|
|
62
|
+
* object keys so it is insensitive to object key order.
|
|
63
|
+
*
|
|
64
|
+
* Type guards the first value.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
*
|
|
68
|
+
* ```ts
|
|
69
|
+
* import {check} from '@augment-vir/assert';
|
|
70
|
+
*
|
|
71
|
+
* check.jsonEquals({a: 'a'}, {a: 'a'}); // true
|
|
72
|
+
*
|
|
73
|
+
* check.jsonEquals({a: {b: 'b'}}, {a: {b: 'c'}}); // false
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* @see
|
|
77
|
+
* - {@link check.notJsonEquals} : the opposite check.
|
|
78
|
+
* - {@link check.entriesEqual} : another deep equality check.
|
|
79
|
+
* - {@link check.deepEquals} : the most thorough (but also slow) deep equality check.
|
|
80
|
+
*/
|
|
64
81
|
jsonEquals: autoGuard(),
|
|
82
|
+
/**
|
|
83
|
+
* Checks that two values are _not_ deeply equal when stringified into JSON. This may not
|
|
84
|
+
* make any sense if the values are not valid JSON. This internally sorts all given object
|
|
85
|
+
* keys so it is insensitive to object key order.
|
|
86
|
+
*
|
|
87
|
+
* Performs no type guarding.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
*
|
|
91
|
+
* ```ts
|
|
92
|
+
* import {check} from '@augment-vir/assert';
|
|
93
|
+
*
|
|
94
|
+
* check.notJsonEquals({a: 'a'}, {a: 'a'}); // false
|
|
95
|
+
*
|
|
96
|
+
* check.notJsonEquals({a: {b: 'b'}}, {a: {b: 'c'}}); // true
|
|
97
|
+
* ```
|
|
98
|
+
*
|
|
99
|
+
* @see
|
|
100
|
+
* - {@link check.jsonEquals} : the opposite check.
|
|
101
|
+
* - {@link check.entriesEqual} : another deep equality check.
|
|
102
|
+
* - {@link check.deepEquals} : the most thorough (but also slow) deep equality check.
|
|
103
|
+
*/
|
|
104
|
+
notJsonEquals: autoGuardSymbol,
|
|
65
105
|
},
|
|
66
|
-
|
|
106
|
+
assertWrap: {
|
|
107
|
+
/**
|
|
108
|
+
* Asserts that two values are deeply equal when stringified into JSON. This will fail or
|
|
109
|
+
* may not make any sense if the values are not valid JSON. This internally sorts all given
|
|
110
|
+
* object keys so it is insensitive to object key order. Returns the first value if the
|
|
111
|
+
* assertion passes.
|
|
112
|
+
*
|
|
113
|
+
* Type guards the first value.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
*
|
|
117
|
+
* ```ts
|
|
118
|
+
* import {assertWrap} from '@augment-vir/assert';
|
|
119
|
+
*
|
|
120
|
+
* assertWrap.jsonEquals({a: 'a'}, {a: 'a'}); // returns `{a: 'a'}`
|
|
121
|
+
*
|
|
122
|
+
* assertWrap.jsonEquals({a: {b: 'b'}}, {a: {b: 'c'}}); // throws an error
|
|
123
|
+
* ```
|
|
124
|
+
*
|
|
125
|
+
* @throws {@link AssertionError} If both inputs are not equal.
|
|
126
|
+
* @see
|
|
127
|
+
* - {@link assertWrap.notJsonEquals} : the opposite assertion.
|
|
128
|
+
* - {@link assertWrap.entriesEqual} : another deep equality assertion.
|
|
129
|
+
* - {@link assertWrap.deepEquals} : the most thorough (but also slow) deep equality assertion.
|
|
130
|
+
*/
|
|
67
131
|
jsonEquals: autoGuard(),
|
|
132
|
+
/**
|
|
133
|
+
* Asserts that two values are _not_ deeply equal when stringified into JSON. This may not
|
|
134
|
+
* make any sense if the values are not valid JSON. This internally sorts all given object
|
|
135
|
+
* keys so it is insensitive to object key order. Returns the first value if the assertion
|
|
136
|
+
* passes.
|
|
137
|
+
*
|
|
138
|
+
* Performs no type guarding.
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
*
|
|
142
|
+
* ```ts
|
|
143
|
+
* import {assertWrap} from '@augment-vir/assert';
|
|
144
|
+
*
|
|
145
|
+
* assertWrap.notJsonEquals({a: 'a'}, {a: 'a'}); // throws an error
|
|
146
|
+
*
|
|
147
|
+
* assertWrap.notJsonEquals({a: {b: 'b'}}, {a: {b: 'c'}}); // returns `{a: {b: 'b'}}`
|
|
148
|
+
* ```
|
|
149
|
+
*
|
|
150
|
+
* @throws {@link AssertionError} If both inputs are not equal.
|
|
151
|
+
* @see
|
|
152
|
+
* - {@link assertWrap.jsonEquals} : the opposite assertion.
|
|
153
|
+
* - {@link assertWrap.entriesEqual} : another deep equality assertion.
|
|
154
|
+
* - {@link assertWrap.deepEquals} : the most thorough (but also slow) deep equality assertion.
|
|
155
|
+
*/
|
|
156
|
+
notJsonEquals: autoGuardSymbol,
|
|
68
157
|
},
|
|
69
|
-
|
|
158
|
+
checkWrap: {
|
|
159
|
+
/**
|
|
160
|
+
* Checks that two values are deeply equal when stringified into JSON. This will fail or may
|
|
161
|
+
* not make any sense if the values are not valid JSON. This internally sorts all given
|
|
162
|
+
* object keys so it is insensitive to object key order. Returns the first value if the
|
|
163
|
+
* check passes.
|
|
164
|
+
*
|
|
165
|
+
* Type guards the first value.
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
*
|
|
169
|
+
* ```ts
|
|
170
|
+
* import {checkWrap} from '@augment-vir/assert';
|
|
171
|
+
*
|
|
172
|
+
* checkWrap.jsonEquals({a: 'a'}, {a: 'a'}); // returns `{a: 'a'}`
|
|
173
|
+
*
|
|
174
|
+
* checkWrap.jsonEquals({a: {b: 'b'}}, {a: {b: 'c'}}); // returns `undefined`
|
|
175
|
+
* ```
|
|
176
|
+
*
|
|
177
|
+
* @see
|
|
178
|
+
* - {@link checkWrap.notJsonEquals} : the opposite check.
|
|
179
|
+
* - {@link checkWrap.entriesEqual} : another deep equality check.
|
|
180
|
+
* - {@link checkWrap.deepEquals} : the most thorough (but also slow) deep equality check.
|
|
181
|
+
*/
|
|
70
182
|
jsonEquals: autoGuard(),
|
|
183
|
+
/**
|
|
184
|
+
* Checks that two values are _not_ deeply equal when stringified into JSON. This may not
|
|
185
|
+
* make any sense if the values are not valid JSON. This internally sorts all given object
|
|
186
|
+
* keys so it is insensitive to object key order. Returns the first value if the check
|
|
187
|
+
* passes.
|
|
188
|
+
*
|
|
189
|
+
* Performs no type guarding.
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
*
|
|
193
|
+
* ```ts
|
|
194
|
+
* import {checkWrap} from '@augment-vir/assert';
|
|
195
|
+
*
|
|
196
|
+
* checkWrap.notJsonEquals({a: 'a'}, {a: 'a'}); // false
|
|
197
|
+
*
|
|
198
|
+
* checkWrap.notJsonEquals({a: {b: 'b'}}, {a: {b: 'c'}}); // true
|
|
199
|
+
* ```
|
|
200
|
+
*
|
|
201
|
+
* @see
|
|
202
|
+
* - {@link checkWrap.jsonEquals} : the opposite check.
|
|
203
|
+
* - {@link checkWrap.entriesEqual} : another deep equality check.
|
|
204
|
+
* - {@link checkWrap.deepEquals} : the most thorough (but also slow) deep equality check.
|
|
205
|
+
*/
|
|
206
|
+
notJsonEquals: autoGuardSymbol,
|
|
71
207
|
},
|
|
72
|
-
|
|
208
|
+
waitUntil: {
|
|
209
|
+
/**
|
|
210
|
+
* Repeatedly calls a callback until its output is deeply equal to the first input when
|
|
211
|
+
* stringified into JSON. This may not make any sense if the values are not valid JSON. This
|
|
212
|
+
* internally sorts all given object keys so it is insensitive to object key order. Once the
|
|
213
|
+
* callback output passes, it is returned. If the attempts time out, an error is thrown.
|
|
214
|
+
*
|
|
215
|
+
* Type guards the first value.
|
|
216
|
+
*
|
|
217
|
+
* @example
|
|
218
|
+
*
|
|
219
|
+
* ```ts
|
|
220
|
+
* import {waitUntil} from '@augment-vir/assert';
|
|
221
|
+
*
|
|
222
|
+
* await waitUntil.jsonEquals({a: 'a'}, () => {
|
|
223
|
+
* return {a: 'a'};
|
|
224
|
+
* }); // returns `{a: 'a'}`
|
|
225
|
+
*
|
|
226
|
+
* await waitUntil.jsonEquals({a: {b: 'c'}}, () => {
|
|
227
|
+
* return {a: {b: 'b'}};
|
|
228
|
+
* }); // throws an error
|
|
229
|
+
* ```
|
|
230
|
+
*
|
|
231
|
+
* @returns The callback output once it passes.
|
|
232
|
+
* @throws {@link AssertionError} On timeout.
|
|
233
|
+
* @see
|
|
234
|
+
* - {@link waitUntil.notJsonEquals} : the opposite assertion.
|
|
235
|
+
* - {@link waitUntil.entriesEqual} : another deep equality assertion.
|
|
236
|
+
* - {@link waitUntil.deepEquals} : the most thorough (but also slow) deep equality assertion.
|
|
237
|
+
*/
|
|
73
238
|
jsonEquals: autoGuard(),
|
|
239
|
+
/**
|
|
240
|
+
* Repeatedly calls a callback until its output is _not_ deeply equal to the first input
|
|
241
|
+
* when stringified into JSON. This may not make any sense if the values are not valid JSON.
|
|
242
|
+
* This internally sorts all given object keys so it is insensitive to object key order.
|
|
243
|
+
* Once the callback output passes, it is returned. If the attempts time out, an error is
|
|
244
|
+
* thrown.
|
|
245
|
+
*
|
|
246
|
+
* Performs no type guarding.
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
*
|
|
250
|
+
* ```ts
|
|
251
|
+
* import {waitUntil} from '@augment-vir/assert';
|
|
252
|
+
*
|
|
253
|
+
* await waitUntil.notJsonEquals({a: 'a'}, () => {
|
|
254
|
+
* return {a: 'a'};
|
|
255
|
+
* }); // throws an error
|
|
256
|
+
*
|
|
257
|
+
* await waitUntil.notJsonEquals({a: {b: 'c'}}, () => {
|
|
258
|
+
* return {a: {b: 'b'}};
|
|
259
|
+
* }); // returns `{a: {b: 'b'}}`
|
|
260
|
+
* ```
|
|
261
|
+
*
|
|
262
|
+
* @returns The callback output once it passes.
|
|
263
|
+
* @throws {@link AssertionError} On timeout.
|
|
264
|
+
* @see
|
|
265
|
+
* - {@link waitUntil.jsonEquals} : the opposite assertion.
|
|
266
|
+
* - {@link waitUntil.entriesEqual} : another not deep equality assertion.
|
|
267
|
+
* - {@link waitUntil.deepEquals} : the most thorough (but also slow) not deep equality assertion.
|
|
268
|
+
*/
|
|
269
|
+
notJsonEquals: autoGuardSymbol,
|
|
74
270
|
},
|
|
75
271
|
};
|