@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.
Files changed (65) hide show
  1. package/README.md +11 -0
  2. package/dist/assertions/boolean.d.ts +443 -17
  3. package/dist/assertions/boolean.js +365 -8
  4. package/dist/assertions/boundary.d.ts +657 -13
  5. package/dist/assertions/boundary.js +537 -5
  6. package/dist/assertions/enum.d.ts +236 -8
  7. package/dist/assertions/enum.js +197 -5
  8. package/dist/assertions/equality/entry-equality.d.ts +287 -11
  9. package/dist/assertions/equality/entry-equality.js +243 -6
  10. package/dist/assertions/equality/json-equality.d.ts +244 -15
  11. package/dist/assertions/equality/json-equality.js +207 -11
  12. package/dist/assertions/equality/simple-equality.d.ts +849 -28
  13. package/dist/assertions/equality/simple-equality.js +712 -6
  14. package/dist/assertions/equality/ts-type-equality.d.ts +37 -1
  15. package/dist/assertions/equality/ts-type-equality.js +13 -1
  16. package/dist/assertions/extendable-assertions.d.ts +288 -120
  17. package/dist/assertions/extendable-assertions.js +32 -60
  18. package/dist/assertions/http.d.ts +217 -10
  19. package/dist/assertions/http.js +182 -6
  20. package/dist/assertions/instance.d.ts +189 -8
  21. package/dist/assertions/instance.js +159 -5
  22. package/dist/assertions/keys.d.ts +658 -13
  23. package/dist/assertions/keys.js +556 -5
  24. package/dist/assertions/length.d.ts +381 -9
  25. package/dist/assertions/length.js +309 -5
  26. package/dist/assertions/nullish.d.ts +169 -7
  27. package/dist/assertions/nullish.js +137 -6
  28. package/dist/assertions/numeric.d.ts +965 -11
  29. package/dist/assertions/numeric.js +819 -1
  30. package/dist/assertions/output.d.ts +107 -7
  31. package/dist/assertions/output.js +92 -5
  32. package/dist/assertions/primitive.d.ts +416 -13
  33. package/dist/assertions/primitive.js +352 -6
  34. package/dist/assertions/promise.d.ts +640 -21
  35. package/dist/assertions/promise.js +536 -15
  36. package/dist/assertions/regexp.d.ts +202 -3
  37. package/dist/assertions/regexp.js +173 -1
  38. package/dist/assertions/runtime-type.d.ts +1822 -41
  39. package/dist/assertions/runtime-type.js +1558 -35
  40. package/dist/assertions/throws.d.ts +265 -17
  41. package/dist/assertions/throws.js +229 -17
  42. package/dist/assertions/uuid.d.ts +233 -10
  43. package/dist/assertions/uuid.js +195 -6
  44. package/dist/assertions/values.d.ts +1086 -15
  45. package/dist/assertions/values.js +907 -6
  46. package/dist/augments/assertion.error.d.ts +2 -1
  47. package/dist/augments/assertion.error.js +2 -1
  48. package/dist/augments/guards/assert-wrap.d.ts +82 -37
  49. package/dist/augments/guards/assert-wrap.js +13 -2
  50. package/dist/augments/guards/assert.d.ts +30 -14
  51. package/dist/augments/guards/assert.js +21 -4
  52. package/dist/augments/guards/check-wrap.d.ts +94 -51
  53. package/dist/augments/guards/check-wrap.js +11 -3
  54. package/dist/augments/guards/check.d.ts +87 -37
  55. package/dist/augments/guards/check.js +9 -2
  56. package/dist/augments/guards/wait-until.d.ts +110 -103
  57. package/dist/augments/guards/wait-until.js +18 -3
  58. package/dist/augments/if-equals.d.ts +4 -2
  59. package/dist/guard-types/assert-wrap-function.d.ts +5 -2
  60. package/dist/guard-types/check-function.d.ts +5 -2
  61. package/dist/guard-types/check-wrap-wrapper-function.d.ts +4 -1
  62. package/dist/guard-types/guard-group.d.ts +7 -8
  63. package/dist/guard-types/wait-until-function.d.ts +8 -3
  64. package/dist/guard-types/wait-until-function.js +1 -1
  65. package/package.json +21 -8
@@ -1,3 +1,4 @@
1
+ import { autoGuardSymbol } from '../guard-types/guard-override.js';
1
2
  import { WaitUntilOptions } from '../guard-types/wait-until-function.js';
2
3
  declare function isPromiseLike(actual: unknown, failureMessage?: string | undefined): asserts actual is PromiseLike<any>;
3
4
  declare function isNotPromiseLike<const Actual>(actual: Actual, failureMessage?: string | undefined): asserts actual is Exclude<Actual, PromiseLike<any>>;
@@ -8,58 +9,676 @@ declare function isNotPromiseLike<const Actual>(actual: Actual, failureMessage?:
8
9
  declare function isPromise(actual: unknown, failureMessage?: string | undefined): asserts actual is Promise<any>;
9
10
  declare function isNotPromise<const Actual>(actual: Actual, failureMessage?: string | undefined): asserts actual is Exclude<Actual, Promise<any>>;
10
11
  export declare const promiseGuards: {
11
- assertions: {
12
+ assert: {
12
13
  /**
13
- * Check if a value is a `PromiseLike`. `PromiseLike` is TypeScript built-in type that simply
14
- * includes a `.then` method. This enables the use of third-party promise implementations that
15
- * aren't instances of the built-in `Promise` class.
14
+ * Asserts that a value is a `PromiseLike`.
15
+ *
16
+ * `PromiseLike` is TypeScript built-in type that has a `.then` method and thus behaves like a
17
+ * promise. This is also referred to as a "thenable". This enables the use of third-party
18
+ * promise implementations that aren't instances of the built-in `Promise` class.
16
19
  *
17
20
  * Type guards the value.
21
+ *
22
+ * @example
23
+ *
24
+ * ```ts
25
+ * import {assert} from '@augment-vir/assert';
26
+ *
27
+ * class CustomThenable {
28
+ * constructor(public value: any) {}
29
+ *
30
+ * then(onFulfilled?: AnyFunction, onRejected?: AnyFunction) {
31
+ * return new CustomThenable(onFulfilled ? onFulfilled(this.value) : this.value);
32
+ * }
33
+ * }
34
+ *
35
+ * assert.isPromiseLike(Promise.resolve(5)); // passes
36
+ * assert.isPromiseLike(new CustomThenable(5)); // passes
37
+ * assert.isPromiseLike(5); // fails
38
+ * ```
39
+ *
40
+ * @throws {@link AssertionError} If the assertion fails.
41
+ * @see
42
+ * - {@link assert.isNotPromiseLike} : the opposite assertion.
43
+ * - {@link assert.isPromise} : the more precise assertion.
18
44
  */
19
45
  isPromiseLike: typeof isPromiseLike;
20
46
  /**
21
- * Check if a value is _not_ a `PromiseLike`. `PromiseLike` is TypeScript built-in type that
22
- * simply includes a `.then` method.
47
+ * Asserts that a value is _not_ a `PromiseLike`.
48
+ *
49
+ * `PromiseLike` is TypeScript built-in type that has a `.then` method and thus behaves like a
50
+ * promise. This is also referred to as a "thenable". This enables the use of third-party
51
+ * promise implementations that aren't instances of the built-in `Promise` class.
23
52
  *
24
53
  * Type guards the value.
54
+ *
55
+ * @example
56
+ *
57
+ * ```ts
58
+ * import {assert} from '@augment-vir/assert';
59
+ *
60
+ * class CustomThenable {
61
+ * constructor(public value: any) {}
62
+ *
63
+ * then(onFulfilled?: AnyFunction, onRejected?: AnyFunction) {
64
+ * return new CustomThenable(onFulfilled ? onFulfilled(this.value) : this.value);
65
+ * }
66
+ * }
67
+ *
68
+ * assert.isNotPromiseLike(Promise.resolve(5)); // fails
69
+ * assert.isNotPromiseLike(new CustomThenable(5)); // fails
70
+ * assert.isNotPromiseLike(5); // passes
71
+ * ```
72
+ *
73
+ * @throws {@link AssertionError} If the assertion fails.
74
+ * @see
75
+ * - {@link assert.isPromiseLike} : the opposite assertion.
76
+ * - {@link assert.isNotPromise} : the more precise assertion.
25
77
  */
26
78
  isNotPromiseLike: typeof isNotPromiseLike;
27
79
  /**
28
- * Check if a value is an instance of the built-in `Promise` class.
80
+ * Asserts that a value is a `Promise` instance.
29
81
  *
30
82
  * Type guards the value.
83
+ *
84
+ * @example
85
+ *
86
+ * ```ts
87
+ * import {assert} from '@augment-vir/assert';
88
+ *
89
+ * class CustomThenable {
90
+ * constructor(public value: any) {}
91
+ *
92
+ * then(onFulfilled?: AnyFunction, onRejected?: AnyFunction) {
93
+ * return new CustomThenable(onFulfilled ? onFulfilled(this.value) : this.value);
94
+ * }
95
+ * }
96
+ *
97
+ * assert.isPromise(Promise.resolve(5)); // passes
98
+ * assert.isPromise(new CustomThenable(5)); // fails
99
+ * assert.isPromise(5); // fails
100
+ * ```
101
+ *
102
+ * @throws {@link AssertionError} If the assertion fails.
103
+ * @see
104
+ * - {@link assert.isNotPromise} : the opposite assertion.
105
+ * - {@link assert.isPromiseLike} : the more lenient assertion.
31
106
  */
32
107
  isPromise: typeof isPromise;
33
108
  /**
34
- * Check if a value is _not_ an instance of the built-in `Promise` class.
109
+ * Asserts that a value is a _not_ `Promise` instance.
35
110
  *
36
111
  * Type guards the value.
112
+ *
113
+ * @example
114
+ *
115
+ * ```ts
116
+ * import {assert} from '@augment-vir/assert';
117
+ *
118
+ * class CustomThenable {
119
+ * constructor(public value: any) {}
120
+ *
121
+ * then(onFulfilled?: AnyFunction, onRejected?: AnyFunction) {
122
+ * return new CustomThenable(onFulfilled ? onFulfilled(this.value) : this.value);
123
+ * }
124
+ * }
125
+ *
126
+ * assert.isNotPromise(Promise.resolve(5)); // fails
127
+ * assert.isNotPromise(new CustomThenable(5)); // passes
128
+ * assert.isNotPromise(5); // passes
129
+ * ```
130
+ *
131
+ * @throws {@link AssertionError} If the assertion fails.
132
+ * @see
133
+ * - {@link assert.isPromise} : the opposite assertion.
134
+ * - {@link assert.isNotPromiseLike} : the more lenient assertion.
37
135
  */
38
136
  isNotPromise: typeof isNotPromise;
39
137
  };
40
- checkOverrides: {
41
- isNotPromise: <const Actual>(actual: Actual, failureMessage?: string | undefined) => actual is Exclude<Actual, Promise<any>>;
138
+ check: {
139
+ /**
140
+ * Checks that a value is a `PromiseLike`.
141
+ *
142
+ * `PromiseLike` is TypeScript built-in type that has a `.then` method and thus behaves like
143
+ * a promise. This is also referred to as a "thenable". This enables the use of third-party
144
+ * promise implementations that aren't instances of the built-in `Promise` class.
145
+ *
146
+ * Type guards the value.
147
+ *
148
+ * @example
149
+ *
150
+ * ```ts
151
+ * import {check} from '@augment-vir/assert';
152
+ *
153
+ * class CustomThenable {
154
+ * constructor(public value: any) {}
155
+ *
156
+ * then(onFulfilled?: AnyFunction, onRejected?: AnyFunction) {
157
+ * return new CustomThenable(
158
+ * onFulfilled ? onFulfilled(this.value) : this.value,
159
+ * );
160
+ * }
161
+ * }
162
+ *
163
+ * check.isPromiseLike(Promise.resolve(5)); // returns `true`
164
+ * check.isPromiseLike(new CustomThenable(5)); // returns `true`
165
+ * check.isPromiseLike(5); // returns `false`
166
+ * ```
167
+ *
168
+ * @see
169
+ * - {@link check.isNotPromiseLike} : the opposite check.
170
+ * - {@link check.isPromise} : the more precise check.
171
+ */
172
+ isPromiseLike: typeof autoGuardSymbol;
173
+ /**
174
+ * Checks that a value is _not_ a `PromiseLike`.
175
+ *
176
+ * `PromiseLike` is TypeScript built-in type that has a `.then` method and thus behaves like
177
+ * a promise. This is also referred to as a "thenable". This enables the use of third-party
178
+ * promise implementations that aren't instances of the built-in `Promise` class.
179
+ *
180
+ * Type guards the value.
181
+ *
182
+ * @example
183
+ *
184
+ * ```ts
185
+ * import {check} from '@augment-vir/assert';
186
+ *
187
+ * class CustomThenable {
188
+ * constructor(public value: any) {}
189
+ *
190
+ * then(onFulfilled?: AnyFunction, onRejected?: AnyFunction) {
191
+ * return new CustomThenable(
192
+ * onFulfilled ? onFulfilled(this.value) : this.value,
193
+ * );
194
+ * }
195
+ * }
196
+ *
197
+ * check.isNotPromiseLike(Promise.resolve(5)); // returns `false`
198
+ * check.isNotPromiseLike(new CustomThenable(5)); // returns `false`
199
+ * check.isNotPromiseLike(5); // returns `true`
200
+ * ```
201
+ *
202
+ * @see
203
+ * - {@link check.isPromiseLike} : the opposite check.
204
+ * - {@link check.isNotPromise} : the more precise check.
205
+ */
42
206
  isNotPromiseLike: <const Actual>(actual: Actual, failureMessage?: string | undefined) => actual is Exclude<Actual, PromiseLike<any>>;
207
+ /**
208
+ * Checks that a value is a `Promise` instance.
209
+ *
210
+ * Type guards the value.
211
+ *
212
+ * @example
213
+ *
214
+ * ```ts
215
+ * import {check} from '@augment-vir/assert';
216
+ *
217
+ * class CustomThenable {
218
+ * constructor(public value: any) {}
219
+ *
220
+ * then(onFulfilled?: AnyFunction, onRejected?: AnyFunction) {
221
+ * return new CustomThenable(
222
+ * onFulfilled ? onFulfilled(this.value) : this.value,
223
+ * );
224
+ * }
225
+ * }
226
+ *
227
+ * check.isPromise(Promise.resolve(5)); // returns `true`
228
+ * check.isPromise(new CustomThenable(5)); // returns `false`
229
+ * check.isPromise(5); // returns `false`
230
+ * ```
231
+ *
232
+ * @see
233
+ * - {@link check.isNotPromise} : the opposite check.
234
+ * - {@link check.isPromiseLike} : the more lenient check.
235
+ */
236
+ isPromise: typeof autoGuardSymbol;
237
+ /**
238
+ * Checks that a value is a _not_ `Promise` instance.
239
+ *
240
+ * Type guards the value.
241
+ *
242
+ * @example
243
+ *
244
+ * ```ts
245
+ * import {check} from '@augment-vir/assert';
246
+ *
247
+ * class CustomThenable {
248
+ * constructor(public value: any) {}
249
+ *
250
+ * then(onFulfilled?: AnyFunction, onRejected?: AnyFunction) {
251
+ * return new CustomThenable(
252
+ * onFulfilled ? onFulfilled(this.value) : this.value,
253
+ * );
254
+ * }
255
+ * }
256
+ *
257
+ * check.isNotPromise(Promise.resolve(5)); // returns `false`
258
+ * check.isNotPromise(new CustomThenable(5)); // returns `true`
259
+ * check.isNotPromise(5); // returns `true`
260
+ * ```
261
+ *
262
+ * @see
263
+ * - {@link check.isPromise} : the opposite check.
264
+ * - {@link check.isNotPromiseLike} : the more lenient check.
265
+ */
266
+ isNotPromise: <const Actual>(actual: Actual, failureMessage?: string | undefined) => actual is Exclude<Actual, Promise<any>>;
43
267
  };
44
- assertWrapOverrides: {
45
- isPromise: <const Actual>(actual: Actual, failureMessage?: string | undefined) => Extract<Actual, Promise<any>>;
46
- isNotPromise: <const Actual>(actual: Actual, failureMessage?: string | undefined) => Exclude<Actual, Promise<any>>;
268
+ assertWrap: {
269
+ /**
270
+ * Asserts that a value is a `PromiseLike`. Returns the value if the assertion passes.
271
+ *
272
+ * `PromiseLike` is TypeScript built-in type that has a `.then` method and thus behaves like
273
+ * a promise. This is also referred to as a "thenable". This enables the use of third-party
274
+ * promise implementations that aren't instances of the built-in `Promise` class.
275
+ *
276
+ * Type guards the value.
277
+ *
278
+ * @example
279
+ *
280
+ * ```ts
281
+ * import {assertWrap} from '@augment-vir/assert';
282
+ *
283
+ * class CustomThenable {
284
+ * constructor(public value: any) {}
285
+ *
286
+ * then(onFulfilled?: AnyFunction, onRejected?: AnyFunction) {
287
+ * return new CustomThenable(
288
+ * onFulfilled ? onFulfilled(this.value) : this.value,
289
+ * );
290
+ * }
291
+ * }
292
+ *
293
+ * assertWrap.isPromiseLike(Promise.resolve(5)); // returns the `Promise` instance
294
+ * assertWrap.isPromiseLike(new CustomThenable(5)); // returns the `CustomThenable` instance
295
+ * assertWrap.isPromiseLike(5); // throws an error
296
+ * ```
297
+ *
298
+ * @returns The value if the assertion passes.
299
+ * @throws {@link AssertionError} If the assertion fails.
300
+ * @see
301
+ * - {@link assertWrap.isNotPromiseLike} : the opposite assertion.
302
+ * - {@link assertWrap.isPromise} : the more precise assertion.
303
+ */
47
304
  isPromiseLike: <const Actual>(actual: Actual, failureMessage?: string | undefined) => Extract<Actual, PromiseLike<any>>;
305
+ /**
306
+ * Asserts that a value is _not_ a `PromiseLike`. Returns the value if the assertion passes.
307
+ *
308
+ * `PromiseLike` is TypeScript built-in type that has a `.then` method and thus behaves like
309
+ * a promise. This is also referred to as a "thenable". This enables the use of third-party
310
+ * promise implementations that aren't instances of the built-in `Promise` class.
311
+ *
312
+ * Type guards the value.
313
+ *
314
+ * @example
315
+ *
316
+ * ```ts
317
+ * import {assertWrap} from '@augment-vir/assert';
318
+ *
319
+ * class CustomThenable {
320
+ * constructor(public value: any) {}
321
+ *
322
+ * then(onFulfilled?: AnyFunction, onRejected?: AnyFunction) {
323
+ * return new CustomThenable(
324
+ * onFulfilled ? onFulfilled(this.value) : this.value,
325
+ * );
326
+ * }
327
+ * }
328
+ *
329
+ * assertWrap.isNotPromiseLike(Promise.resolve(5)); // throws an error
330
+ * assertWrap.isNotPromiseLike(new CustomThenable(5)); // throws an error
331
+ * assertWrap.isNotPromiseLike(5); // returns `5`
332
+ * ```
333
+ *
334
+ * @returns The value if the assertion passes.
335
+ * @throws {@link AssertionError} If the assertion fails.
336
+ * @see
337
+ * - {@link assertWrap.isPromiseLike} : the opposite assertion.
338
+ * - {@link assertWrap.isNotPromise} : the more precise assertion.
339
+ */
48
340
  isNotPromiseLike: <const Actual>(actual: Actual, failureMessage?: string | undefined) => Exclude<Actual, PromiseLike<any>>;
341
+ /**
342
+ * Asserts that a value is a `Promise` instance. Returns the value if the assertion passes.
343
+ *
344
+ * Type guards the value.
345
+ *
346
+ * @example
347
+ *
348
+ * ```ts
349
+ * import {assertWrap} from '@augment-vir/assert';
350
+ *
351
+ * class CustomThenable {
352
+ * constructor(public value: any) {}
353
+ *
354
+ * then(onFulfilled?: AnyFunction, onRejected?: AnyFunction) {
355
+ * return new CustomThenable(
356
+ * onFulfilled ? onFulfilled(this.value) : this.value,
357
+ * );
358
+ * }
359
+ * }
360
+ *
361
+ * assertWrap.isPromise(Promise.resolve(5)); // returns the `Promise` instance
362
+ * assertWrap.isPromise(new CustomThenable(5)); // throws an error
363
+ * assertWrap.isPromise(5); // throws an error
364
+ * ```
365
+ *
366
+ * @returns The value if the assertion passes.
367
+ * @throws {@link AssertionError} If the assertion fails.
368
+ * @see
369
+ * - {@link assertWrap.isNotPromise} : the opposite assertion.
370
+ * - {@link assertWrap.isPromiseLike} : the more lenient assertion.
371
+ */
372
+ isPromise: <const Actual>(actual: Actual, failureMessage?: string | undefined) => Extract<Actual, Promise<any>>;
373
+ /**
374
+ * Asserts that a value is a _not_ `Promise` instance. Returns the value if the assertion
375
+ * passes.
376
+ *
377
+ * Type guards the value.
378
+ *
379
+ * @example
380
+ *
381
+ * ```ts
382
+ * import {assertWrap} from '@augment-vir/assert';
383
+ *
384
+ * class CustomThenable {
385
+ * constructor(public value: any) {}
386
+ *
387
+ * then(onFulfilled?: AnyFunction, onRejected?: AnyFunction) {
388
+ * return new CustomThenable(
389
+ * onFulfilled ? onFulfilled(this.value) : this.value,
390
+ * );
391
+ * }
392
+ * }
393
+ *
394
+ * assertWrap.isNotPromise(Promise.resolve(5)); // throws an error
395
+ * assertWrap.isNotPromise(new CustomThenable(5)); // returns the `CustomThenable` promise
396
+ * assertWrap.isNotPromise(5); // returns `5`
397
+ * ```
398
+ *
399
+ * @returns The value if the assertion passes.
400
+ * @throws {@link AssertionError} If the assertion fails.
401
+ * @see
402
+ * - {@link assertWrap.isPromise} : the opposite assertion.
403
+ * - {@link assertWrap.isNotPromiseLike} : the more lenient assertion.
404
+ */
405
+ isNotPromise: <const Actual>(actual: Actual, failureMessage?: string | undefined) => Exclude<Actual, Promise<any>>;
49
406
  };
50
- checkWrapOverrides: {
407
+ checkWrap: {
408
+ /**
409
+ * Checks that a value is a `PromiseLike`. Returns the value if the check passes, otherwise
410
+ * `undefined`.
411
+ *
412
+ * `PromiseLike` is TypeScript built-in type that has a `.then` method and thus behaves like
413
+ * a promise. This is also referred to as a "thenable". This enables the use of third-party
414
+ * promise implementations that aren't instances of the built-in `Promise` class.
415
+ *
416
+ * Type guards the value.
417
+ *
418
+ * @example
419
+ *
420
+ * ```ts
421
+ * import {checkWrap} from '@augment-vir/assert';
422
+ *
423
+ * class CustomThenable {
424
+ * constructor(public value: any) {}
425
+ *
426
+ * then(onFulfilled?: AnyFunction, onRejected?: AnyFunction) {
427
+ * return new CustomThenable(
428
+ * onFulfilled ? onFulfilled(this.value) : this.value,
429
+ * );
430
+ * }
431
+ * }
432
+ *
433
+ * checkWrap.isPromiseLike(Promise.resolve(5)); // returns `true`
434
+ * checkWrap.isPromiseLike(new CustomThenable(5)); // returns `true`
435
+ * checkWrap.isPromiseLike(5); // returns `false`
436
+ * ```
437
+ *
438
+ * @see
439
+ * - {@link checkWrap.isNotPromiseLike} : the opposite check.
440
+ * - {@link checkWrap.isPromise} : the more precise check.
441
+ */
51
442
  isNotPromise: <const Actual>(actual: Actual, failureMessage?: string | undefined) => Exclude<Actual, Promise<any>> | undefined;
443
+ /**
444
+ * Checks that a value is _not_ a `PromiseLike`. Returns the value if the check passes,
445
+ * otherwise `undefined`.
446
+ *
447
+ * `PromiseLike` is TypeScript built-in type that has a `.then` method and thus behaves like
448
+ * a promise. This is also referred to as a "thenable". This enables the use of third-party
449
+ * promise implementations that aren't instances of the built-in `Promise` class.
450
+ *
451
+ * Type guards the value.
452
+ *
453
+ * @example
454
+ *
455
+ * ```ts
456
+ * import {checkWrap} from '@augment-vir/assert';
457
+ *
458
+ * class CustomThenable {
459
+ * constructor(public value: any) {}
460
+ *
461
+ * then(onFulfilled?: AnyFunction, onRejected?: AnyFunction) {
462
+ * return new CustomThenable(
463
+ * onFulfilled ? onFulfilled(this.value) : this.value,
464
+ * );
465
+ * }
466
+ * }
467
+ *
468
+ * checkWrap.isNotPromiseLike(Promise.resolve(5)); // returns `false`
469
+ * checkWrap.isNotPromiseLike(new CustomThenable(5)); // returns `false`
470
+ * checkWrap.isNotPromiseLike(5); // returns `true`
471
+ * ```
472
+ *
473
+ * @see
474
+ * - {@link checkWrap.isPromiseLike} : the opposite check.
475
+ * - {@link checkWrap.isNotPromise} : the more precise check.
476
+ */
52
477
  isNotPromiseLike: <const Actual>(actual: Actual, failureMessage?: string | undefined) => Exclude<Actual, PromiseLike<any>> | undefined;
478
+ /**
479
+ * Checks that a value is a `Promise` instance. Returns the value if the check passes,
480
+ * otherwise `undefined`.
481
+ *
482
+ * Type guards the value.
483
+ *
484
+ * @example
485
+ *
486
+ * ```ts
487
+ * import {checkWrap} from '@augment-vir/assert';
488
+ *
489
+ * class CustomThenable {
490
+ * constructor(public value: any) {}
491
+ *
492
+ * then(onFulfilled?: AnyFunction, onRejected?: AnyFunction) {
493
+ * return new CustomThenable(
494
+ * onFulfilled ? onFulfilled(this.value) : this.value,
495
+ * );
496
+ * }
497
+ * }
498
+ *
499
+ * checkWrap.isPromise(Promise.resolve(5)); // returns `true`
500
+ * checkWrap.isPromise(new CustomThenable(5)); // returns `false`
501
+ * checkWrap.isPromise(5); // returns `false`
502
+ * ```
503
+ *
504
+ * @see
505
+ * - {@link checkWrap.isNotPromise} : the opposite check.
506
+ * - {@link checkWrap.isPromiseLike} : the more lenient check.
507
+ */
508
+ isPromise: typeof autoGuardSymbol;
509
+ /**
510
+ * Checks that a value is a _not_ `Promise` instance. Returns the value if the check passes,
511
+ * otherwise `undefined`.
512
+ *
513
+ * Type guards the value.
514
+ *
515
+ * @example
516
+ *
517
+ * ```ts
518
+ * import {checkWrap} from '@augment-vir/assert';
519
+ *
520
+ * class CustomThenable {
521
+ * constructor(public value: any) {}
522
+ *
523
+ * then(onFulfilled?: AnyFunction, onRejected?: AnyFunction) {
524
+ * return new CustomThenable(
525
+ * onFulfilled ? onFulfilled(this.value) : this.value,
526
+ * );
527
+ * }
528
+ * }
529
+ *
530
+ * checkWrap.isNotPromise(Promise.resolve(5)); // returns `false`
531
+ * checkWrap.isNotPromise(new CustomThenable(5)); // returns `true`
532
+ * checkWrap.isNotPromise(5); // returns `true`
533
+ * ```
534
+ *
535
+ * @see
536
+ * - {@link checkWrap.isPromise} : the opposite check.
537
+ * - {@link checkWrap.isNotPromiseLike} : the more lenient check.
538
+ */
539
+ isPromiseLike: typeof autoGuardSymbol;
53
540
  };
54
- /**
55
- * These overrides must explicitly use `createWaitUntil` so they can pass in `true` for the
56
- * second parameter, `requireSynchronousResult`.
57
- */
58
- waitUntilOverrides: {
59
- isPromise: <const Actual>(callback: () => Actual, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined) => Promise<Extract<Actual, Promise<any>>>;
60
- isNotPromise: <const Actual>(callback: () => Actual, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined) => Promise<Exclude<Actual, Promise<any>>>;
541
+ waitUntil: {
542
+ /**
543
+ * Repeatedly calls a callback until its output is a `PromiseLike`. Once the callback output
544
+ * passes, it is returned. If the attempts time out, an error is thrown.
545
+ *
546
+ * `PromiseLike` is TypeScript built-in type that has a `.then` method and thus behaves like
547
+ * a promise. This is also referred to as a "thenable". This enables the use of third-party
548
+ * promise implementations that aren't instances of the built-in `Promise` class.
549
+ *
550
+ * Type guards the value.
551
+ *
552
+ * @example
553
+ *
554
+ * ```ts
555
+ * import {waitUntil} from '@augment-vir/assert';
556
+ *
557
+ * class CustomThenable {
558
+ * constructor(public value: any) {}
559
+ *
560
+ * then(onFulfilled?: AnyFunction, onRejected?: AnyFunction) {
561
+ * return new CustomThenable(
562
+ * onFulfilled ? onFulfilled(this.value) : this.value,
563
+ * );
564
+ * }
565
+ * }
566
+ *
567
+ * await waitUntil.isPromiseLike(() => Promise.resolve(5)); // returns the resolved `5`
568
+ * await waitUntil.isPromiseLike(() => new CustomThenable(5)); // returns the resolved `5`
569
+ * await waitUntil.isPromiseLike(() => 5); // throws an error
570
+ * ```
571
+ *
572
+ * @returns The callback output once it passes.
573
+ * @throws {@link AssertionError} If the assertion fails.
574
+ * @see
575
+ * - {@link waitUntil.isNotPromiseLike} : the opposite assertion.
576
+ * - {@link waitUntil.isPromise} : the more precise assertion.
577
+ */
61
578
  isPromiseLike: <const Actual>(callback: () => Actual, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined) => Promise<Extract<Actual, PromiseLike<any>>>;
579
+ /**
580
+ * Repeatedly calls a callback until its output is _not_ a `PromiseLike`. Once the callback
581
+ * output passes, it is returned. If the attempts time out, an error is thrown.
582
+ *
583
+ * `PromiseLike` is TypeScript built-in type that has a `.then` method and thus behaves like
584
+ * a promise. This is also referred to as a "thenable". This enables the use of third-party
585
+ * promise implementations that aren't instances of the built-in `Promise` class.
586
+ *
587
+ * Type guards the value.
588
+ *
589
+ * @example
590
+ *
591
+ * ```ts
592
+ * import {waitUntil} from '@augment-vir/assert';
593
+ *
594
+ * class CustomThenable {
595
+ * constructor(public value: any) {}
596
+ *
597
+ * then(onFulfilled?: AnyFunction, onRejected?: AnyFunction) {
598
+ * return new CustomThenable(
599
+ * onFulfilled ? onFulfilled(this.value) : this.value,
600
+ * );
601
+ * }
602
+ * }
603
+ *
604
+ * await waitUntil.isNotPromiseLike(() => Promise.resolve(5)); // throws an error
605
+ * await waitUntil.isNotPromiseLike(() => new CustomThenable(5)); // throws an error
606
+ * await waitUntil.isNotPromiseLike(() => 5); // returns `5`
607
+ * ```
608
+ *
609
+ * @returns The callback output once it passes.
610
+ * @throws {@link AssertionError} If the assertion fails.
611
+ * @see
612
+ * - {@link waitUntil.isPromiseLike} : the opposite assertion.
613
+ * - {@link waitUntil.isNotPromise} : the more precise assertion.
614
+ */
62
615
  isNotPromiseLike: <const Actual>(callback: () => Actual, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined) => Promise<Exclude<Actual, PromiseLike<any>>>;
616
+ /**
617
+ * Repeatedly calls a callback until its output is a `Promise` instance. Once the callback
618
+ * output passes, it is returned. If the attempts time out, an error is thrown.
619
+ *
620
+ * Type guards the value.
621
+ *
622
+ * @example
623
+ *
624
+ * ```ts
625
+ * import {waitUntil} from '@augment-vir/assert';
626
+ *
627
+ * class CustomThenable {
628
+ * constructor(public value: any) {}
629
+ *
630
+ * then(onFulfilled?: AnyFunction, onRejected?: AnyFunction) {
631
+ * return new CustomThenable(
632
+ * onFulfilled ? onFulfilled(this.value) : this.value,
633
+ * );
634
+ * }
635
+ * }
636
+ *
637
+ * await waitUntil.isPromise(() => Promise.resolve(5)); // returns the resolved `5`
638
+ * await waitUntil.isPromise(() => new CustomThenable(5)); // throws an error
639
+ * await waitUntil.isPromise(() => 5); // throws an error
640
+ * ```
641
+ *
642
+ * @returns The callback output once it passes.
643
+ * @throws {@link AssertionError} If the assertion fails.
644
+ * @see
645
+ * - {@link waitUntil.isNotPromise} : the opposite assertion.
646
+ * - {@link waitUntil.isPromiseLike} : the more lenient assertion.
647
+ */
648
+ isPromise: <const Actual>(callback: () => Actual, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined) => Promise<Extract<Actual, Promise<any>>>;
649
+ /**
650
+ * Repeatedly calls a callback until its output is a _not_ `Promise` instance. Once the
651
+ * callback output passes, it is returned. If the attempts time out, an error is thrown.
652
+ *
653
+ * Type guards the value.
654
+ *
655
+ * @example
656
+ *
657
+ * ```ts
658
+ * import {waitUntil} from '@augment-vir/assert';
659
+ *
660
+ * class CustomThenable {
661
+ * constructor(public value: any) {}
662
+ *
663
+ * then(onFulfilled?: AnyFunction, onRejected?: AnyFunction) {
664
+ * return new CustomThenable(
665
+ * onFulfilled ? onFulfilled(this.value) : this.value,
666
+ * );
667
+ * }
668
+ * }
669
+ *
670
+ * await waitUntil.isNotPromise(() => Promise.resolve(5)); // throws an error
671
+ * await waitUntil.isNotPromise(() => new CustomThenable(5)); // returns the resolved `5`
672
+ * await waitUntil.isNotPromise(() => 5); // returns the resolved `5`
673
+ * ```
674
+ *
675
+ * @returns The callback output once it passes.
676
+ * @throws {@link AssertionError} If the assertion fails.
677
+ * @see
678
+ * - {@link waitUntil.isPromise} : the opposite assertion.
679
+ * - {@link waitUntil.isNotPromiseLike} : the more lenient assertion.
680
+ */
681
+ isNotPromise: <const Actual>(callback: () => Actual, options?: WaitUntilOptions | undefined, failureMessage?: string | undefined) => Promise<Exclude<Actual, Promise<any>>>;
63
682
  };
64
683
  };
65
684
  export {};