@xylabs/vitest-matchers 7.0.7 → 8.0.0
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 +1 -637
- package/dist/neutral/index.d.ts +1 -1
- package/dist/neutral/index.d.ts.map +1 -1
- package/dist/neutral/index.mjs +2 -368
- package/dist/neutral/index.mjs.map +3 -3
- package/dist/neutral/model.d.ts +1 -1
- package/dist/neutral/model.d.ts.map +1 -1
- package/dist/neutral/model.mjs +2 -0
- package/dist/neutral/model.mjs.map +3 -3
- package/package.json +10 -12
- package/dist/neutral/customMatchers.d.ts +0 -135
- package/dist/neutral/customMatchers.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -1,639 +1,3 @@
|
|
|
1
|
-
[![logo][]](https://xylabs.com)
|
|
2
|
-
|
|
3
1
|
# @xylabs/vitest-matchers
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
[![license][license-badge]][license-link]
|
|
7
|
-
|
|
8
|
-
> Base functionality used throughout XY Labs TypeScript/JavaScript libraries
|
|
9
|
-
|
|
10
|
-
## Install
|
|
11
|
-
|
|
12
|
-
Using npm:
|
|
13
|
-
|
|
14
|
-
```sh
|
|
15
|
-
npm install {{name}}
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
Using yarn:
|
|
19
|
-
|
|
20
|
-
```sh
|
|
21
|
-
yarn add {{name}}
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
Using pnpm:
|
|
25
|
-
|
|
26
|
-
```sh
|
|
27
|
-
pnpm add {{name}}
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
Using bun:
|
|
31
|
-
|
|
32
|
-
```sh
|
|
33
|
-
bun add {{name}}
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
## License
|
|
38
|
-
|
|
39
|
-
See the [LICENSE](LICENSE) file for license rights and limitations (LGPL-3.0-only).
|
|
40
|
-
|
|
41
|
-
## Reference
|
|
42
|
-
|
|
43
|
-
### packages
|
|
44
|
-
|
|
45
|
-
### vitest-matchers
|
|
46
|
-
|
|
47
|
-
### .temp-typedoc
|
|
48
|
-
|
|
49
|
-
### interfaces
|
|
50
|
-
|
|
51
|
-
### <a id="ExpectationResult"></a>ExpectationResult
|
|
52
|
-
|
|
53
|
-
[**@xylabs/vitest-matchers**](#../README)
|
|
54
|
-
|
|
55
|
-
***
|
|
56
|
-
|
|
57
|
-
Result returned by a custom matcher function.
|
|
58
|
-
|
|
59
|
-
## Properties
|
|
60
|
-
|
|
61
|
-
### actual?
|
|
62
|
-
|
|
63
|
-
```ts
|
|
64
|
-
optional actual?: unknown;
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
The actual value received by the matcher.
|
|
68
|
-
|
|
69
|
-
***
|
|
70
|
-
|
|
71
|
-
### expected?
|
|
72
|
-
|
|
73
|
-
```ts
|
|
74
|
-
optional expected?: unknown;
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
The expected value the matcher compared against.
|
|
78
|
-
|
|
79
|
-
***
|
|
80
|
-
|
|
81
|
-
### message
|
|
82
|
-
|
|
83
|
-
```ts
|
|
84
|
-
message: () => string;
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
Returns a human-readable failure or negation message.
|
|
88
|
-
|
|
89
|
-
### Returns
|
|
90
|
-
|
|
91
|
-
`string`
|
|
92
|
-
|
|
93
|
-
***
|
|
94
|
-
|
|
95
|
-
### pass
|
|
96
|
-
|
|
97
|
-
```ts
|
|
98
|
-
pass: boolean;
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
Whether the matcher assertion passed.
|
|
102
|
-
|
|
103
|
-
### variables
|
|
104
|
-
|
|
105
|
-
### <a id="matchers"></a>matchers
|
|
106
|
-
|
|
107
|
-
[**@xylabs/vitest-matchers**](#../README)
|
|
108
|
-
|
|
109
|
-
***
|
|
110
|
-
|
|
111
|
-
```ts
|
|
112
|
-
const matchers: object;
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
Collection of custom Vitest matchers extending the built-in `expect` assertions.
|
|
116
|
-
|
|
117
|
-
## Type Declaration
|
|
118
|
-
|
|
119
|
-
### toBeArrayOfSize()
|
|
120
|
-
|
|
121
|
-
```ts
|
|
122
|
-
toBeArrayOfSize(received, expectedSize): ExpectationResult;
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
Asserts the received value is an array with the specified length.
|
|
126
|
-
|
|
127
|
-
### Parameters
|
|
128
|
-
|
|
129
|
-
#### received
|
|
130
|
-
|
|
131
|
-
`unknown`
|
|
132
|
-
|
|
133
|
-
The value to check.
|
|
134
|
-
|
|
135
|
-
#### expectedSize
|
|
136
|
-
|
|
137
|
-
`number`
|
|
138
|
-
|
|
139
|
-
The expected array length.
|
|
140
|
-
|
|
141
|
-
### Returns
|
|
142
|
-
|
|
143
|
-
[`ExpectationResult`](#../interfaces/ExpectationResult)
|
|
144
|
-
|
|
145
|
-
### toBeArray()
|
|
146
|
-
|
|
147
|
-
```ts
|
|
148
|
-
toBeArray(received): ExpectationResult;
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
Asserts the received value is an array.
|
|
152
|
-
|
|
153
|
-
### Parameters
|
|
154
|
-
|
|
155
|
-
#### received
|
|
156
|
-
|
|
157
|
-
`unknown`
|
|
158
|
-
|
|
159
|
-
The value to check.
|
|
160
|
-
|
|
161
|
-
### Returns
|
|
162
|
-
|
|
163
|
-
[`ExpectationResult`](#../interfaces/ExpectationResult)
|
|
164
|
-
|
|
165
|
-
### toBeOneOf()
|
|
166
|
-
|
|
167
|
-
```ts
|
|
168
|
-
toBeOneOf(received, expected): ExpectationResult;
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
Asserts the received value is one of the values in the expected array.
|
|
172
|
-
|
|
173
|
-
### Parameters
|
|
174
|
-
|
|
175
|
-
#### received
|
|
176
|
-
|
|
177
|
-
`unknown`
|
|
178
|
-
|
|
179
|
-
The value to check.
|
|
180
|
-
|
|
181
|
-
#### expected
|
|
182
|
-
|
|
183
|
-
`unknown`[]
|
|
184
|
-
|
|
185
|
-
The array of acceptable values.
|
|
186
|
-
|
|
187
|
-
### Returns
|
|
188
|
-
|
|
189
|
-
[`ExpectationResult`](#../interfaces/ExpectationResult)
|
|
190
|
-
|
|
191
|
-
### toBeNegative()
|
|
192
|
-
|
|
193
|
-
```ts
|
|
194
|
-
toBeNegative(received): ExpectationResult;
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
Asserts the received number is negative (less than zero).
|
|
198
|
-
|
|
199
|
-
### Parameters
|
|
200
|
-
|
|
201
|
-
#### received
|
|
202
|
-
|
|
203
|
-
`number`
|
|
204
|
-
|
|
205
|
-
The number to check.
|
|
206
|
-
|
|
207
|
-
### Returns
|
|
208
|
-
|
|
209
|
-
[`ExpectationResult`](#../interfaces/ExpectationResult)
|
|
210
|
-
|
|
211
|
-
### toBePositive()
|
|
212
|
-
|
|
213
|
-
```ts
|
|
214
|
-
toBePositive(received): ExpectationResult;
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
Asserts the received number is positive (greater than zero).
|
|
218
|
-
|
|
219
|
-
### Parameters
|
|
220
|
-
|
|
221
|
-
#### received
|
|
222
|
-
|
|
223
|
-
`number`
|
|
224
|
-
|
|
225
|
-
The number to check.
|
|
226
|
-
|
|
227
|
-
### Returns
|
|
228
|
-
|
|
229
|
-
[`ExpectationResult`](#../interfaces/ExpectationResult)
|
|
230
|
-
|
|
231
|
-
### toBeNumber
|
|
232
|
-
|
|
233
|
-
```ts
|
|
234
|
-
toBeNumber: (received) => ExpectationResult;
|
|
235
|
-
```
|
|
236
|
-
|
|
237
|
-
Asserts the received value is of type `number` and not NaN.
|
|
238
|
-
|
|
239
|
-
### Parameters
|
|
240
|
-
|
|
241
|
-
#### received
|
|
242
|
-
|
|
243
|
-
`unknown`
|
|
244
|
-
|
|
245
|
-
The value to check.
|
|
246
|
-
|
|
247
|
-
### Returns
|
|
248
|
-
|
|
249
|
-
[`ExpectationResult`](#../interfaces/ExpectationResult)
|
|
250
|
-
|
|
251
|
-
### toBeFunction
|
|
252
|
-
|
|
253
|
-
```ts
|
|
254
|
-
toBeFunction: (received) => ExpectationResult;
|
|
255
|
-
```
|
|
256
|
-
|
|
257
|
-
Asserts the received value is of type `function`.
|
|
258
|
-
|
|
259
|
-
### Parameters
|
|
260
|
-
|
|
261
|
-
#### received
|
|
262
|
-
|
|
263
|
-
`unknown`
|
|
264
|
-
|
|
265
|
-
The value to check.
|
|
266
|
-
|
|
267
|
-
### Returns
|
|
268
|
-
|
|
269
|
-
[`ExpectationResult`](#../interfaces/ExpectationResult)
|
|
270
|
-
|
|
271
|
-
### toBeString
|
|
272
|
-
|
|
273
|
-
```ts
|
|
274
|
-
toBeString: (received) => ExpectationResult;
|
|
275
|
-
```
|
|
276
|
-
|
|
277
|
-
Asserts the received value is of type `string`.
|
|
278
|
-
|
|
279
|
-
### Parameters
|
|
280
|
-
|
|
281
|
-
#### received
|
|
282
|
-
|
|
283
|
-
`unknown`
|
|
284
|
-
|
|
285
|
-
The value to check.
|
|
286
|
-
|
|
287
|
-
### Returns
|
|
288
|
-
|
|
289
|
-
[`ExpectationResult`](#../interfaces/ExpectationResult)
|
|
290
|
-
|
|
291
|
-
### toBeObject()
|
|
292
|
-
|
|
293
|
-
```ts
|
|
294
|
-
toBeObject(received): ExpectationResult;
|
|
295
|
-
```
|
|
296
|
-
|
|
297
|
-
Asserts the received value is a plain object (not an array or null).
|
|
298
|
-
|
|
299
|
-
### Parameters
|
|
300
|
-
|
|
301
|
-
#### received
|
|
302
|
-
|
|
303
|
-
`unknown`
|
|
304
|
-
|
|
305
|
-
The value to check.
|
|
306
|
-
|
|
307
|
-
### Returns
|
|
308
|
-
|
|
309
|
-
[`ExpectationResult`](#../interfaces/ExpectationResult)
|
|
310
|
-
|
|
311
|
-
### toBeInteger()
|
|
312
|
-
|
|
313
|
-
```ts
|
|
314
|
-
toBeInteger(received): ExpectationResult;
|
|
315
|
-
```
|
|
316
|
-
|
|
317
|
-
Asserts the received number is an integer.
|
|
318
|
-
|
|
319
|
-
### Parameters
|
|
320
|
-
|
|
321
|
-
#### received
|
|
322
|
-
|
|
323
|
-
`number`
|
|
324
|
-
|
|
325
|
-
The number to check.
|
|
326
|
-
|
|
327
|
-
### Returns
|
|
328
|
-
|
|
329
|
-
[`ExpectationResult`](#../interfaces/ExpectationResult)
|
|
330
|
-
|
|
331
|
-
### toBeFalse()
|
|
332
|
-
|
|
333
|
-
```ts
|
|
334
|
-
toBeFalse(received): ExpectationResult;
|
|
335
|
-
```
|
|
336
|
-
|
|
337
|
-
Asserts the received value is strictly `false`.
|
|
338
|
-
|
|
339
|
-
### Parameters
|
|
340
|
-
|
|
341
|
-
#### received
|
|
342
|
-
|
|
343
|
-
`unknown`
|
|
344
|
-
|
|
345
|
-
The value to check.
|
|
346
|
-
|
|
347
|
-
### Returns
|
|
348
|
-
|
|
349
|
-
[`ExpectationResult`](#../interfaces/ExpectationResult)
|
|
350
|
-
|
|
351
|
-
### toBeTrue()
|
|
352
|
-
|
|
353
|
-
```ts
|
|
354
|
-
toBeTrue(received): ExpectationResult;
|
|
355
|
-
```
|
|
356
|
-
|
|
357
|
-
Asserts the received value is strictly `true`.
|
|
358
|
-
|
|
359
|
-
### Parameters
|
|
360
|
-
|
|
361
|
-
#### received
|
|
362
|
-
|
|
363
|
-
`unknown`
|
|
364
|
-
|
|
365
|
-
The value to check.
|
|
366
|
-
|
|
367
|
-
### Returns
|
|
368
|
-
|
|
369
|
-
[`ExpectationResult`](#../interfaces/ExpectationResult)
|
|
370
|
-
|
|
371
|
-
### toContainAllValues()
|
|
372
|
-
|
|
373
|
-
```ts
|
|
374
|
-
toContainAllValues(received, expectedValues): object;
|
|
375
|
-
```
|
|
376
|
-
|
|
377
|
-
Asserts that all expected values are present in the received array or object values.
|
|
378
|
-
|
|
379
|
-
### Parameters
|
|
380
|
-
|
|
381
|
-
#### received
|
|
382
|
-
|
|
383
|
-
`unknown`
|
|
384
|
-
|
|
385
|
-
The array or object to check.
|
|
386
|
-
|
|
387
|
-
#### expectedValues
|
|
388
|
-
|
|
389
|
-
`unknown`[]
|
|
390
|
-
|
|
391
|
-
The values that must all be present.
|
|
392
|
-
|
|
393
|
-
### Returns
|
|
394
|
-
|
|
395
|
-
`object`
|
|
396
|
-
|
|
397
|
-
#### pass
|
|
398
|
-
|
|
399
|
-
```ts
|
|
400
|
-
pass: boolean = false;
|
|
401
|
-
```
|
|
402
|
-
|
|
403
|
-
#### message
|
|
404
|
-
|
|
405
|
-
```ts
|
|
406
|
-
message: () => string;
|
|
407
|
-
```
|
|
408
|
-
|
|
409
|
-
##### Returns
|
|
410
|
-
|
|
411
|
-
`string`
|
|
412
|
-
|
|
413
|
-
### toContainKey()
|
|
414
|
-
|
|
415
|
-
```ts
|
|
416
|
-
toContainKey(received, key): object;
|
|
417
|
-
```
|
|
418
|
-
|
|
419
|
-
Asserts that the received object contains the specified key.
|
|
420
|
-
|
|
421
|
-
### Parameters
|
|
422
|
-
|
|
423
|
-
#### received
|
|
424
|
-
|
|
425
|
-
`object`
|
|
426
|
-
|
|
427
|
-
The object to check.
|
|
428
|
-
|
|
429
|
-
#### key
|
|
430
|
-
|
|
431
|
-
`string`
|
|
432
|
-
|
|
433
|
-
The key that should be present.
|
|
434
|
-
|
|
435
|
-
### Returns
|
|
436
|
-
|
|
437
|
-
`object`
|
|
438
|
-
|
|
439
|
-
#### pass
|
|
440
|
-
|
|
441
|
-
```ts
|
|
442
|
-
pass: boolean = true;
|
|
443
|
-
```
|
|
444
|
-
|
|
445
|
-
#### message
|
|
446
|
-
|
|
447
|
-
```ts
|
|
448
|
-
message: () => string;
|
|
449
|
-
```
|
|
450
|
-
|
|
451
|
-
##### Returns
|
|
452
|
-
|
|
453
|
-
`string`
|
|
454
|
-
|
|
455
|
-
### toInclude()
|
|
456
|
-
|
|
457
|
-
```ts
|
|
458
|
-
toInclude(received, value): object;
|
|
459
|
-
```
|
|
460
|
-
|
|
461
|
-
Asserts that the received array, string, or object values include the specified value.
|
|
462
|
-
|
|
463
|
-
### Parameters
|
|
464
|
-
|
|
465
|
-
#### received
|
|
466
|
-
|
|
467
|
-
`unknown`
|
|
468
|
-
|
|
469
|
-
The array, string, or object to search within.
|
|
470
|
-
|
|
471
|
-
#### value
|
|
472
|
-
|
|
473
|
-
`any`
|
|
474
|
-
|
|
475
|
-
The value to look for.
|
|
476
|
-
|
|
477
|
-
### Returns
|
|
478
|
-
|
|
479
|
-
`object`
|
|
480
|
-
|
|
481
|
-
#### pass
|
|
482
|
-
|
|
483
|
-
```ts
|
|
484
|
-
pass: boolean;
|
|
485
|
-
```
|
|
486
|
-
|
|
487
|
-
#### message
|
|
488
|
-
|
|
489
|
-
```ts
|
|
490
|
-
message: () => string;
|
|
491
|
-
```
|
|
492
|
-
|
|
493
|
-
##### Returns
|
|
494
|
-
|
|
495
|
-
`string`
|
|
496
|
-
|
|
497
|
-
### toIncludeAllMembers()
|
|
498
|
-
|
|
499
|
-
```ts
|
|
500
|
-
toIncludeAllMembers(received, expected): ExpectationResult;
|
|
501
|
-
```
|
|
502
|
-
|
|
503
|
-
Asserts that the received array includes all members of the expected array.
|
|
504
|
-
|
|
505
|
-
### Parameters
|
|
506
|
-
|
|
507
|
-
#### received
|
|
508
|
-
|
|
509
|
-
`unknown`[]
|
|
510
|
-
|
|
511
|
-
The array to check.
|
|
512
|
-
|
|
513
|
-
#### expected
|
|
514
|
-
|
|
515
|
-
`unknown`[]
|
|
516
|
-
|
|
517
|
-
The members that must all be present.
|
|
518
|
-
|
|
519
|
-
### Returns
|
|
520
|
-
|
|
521
|
-
[`ExpectationResult`](#../interfaces/ExpectationResult)
|
|
522
|
-
|
|
523
|
-
### toContainAllKeys()
|
|
524
|
-
|
|
525
|
-
```ts
|
|
526
|
-
toContainAllKeys(received, expectedKeys): ExpectationResult;
|
|
527
|
-
```
|
|
528
|
-
|
|
529
|
-
Asserts that the received object contains all of the specified keys.
|
|
530
|
-
|
|
531
|
-
### Parameters
|
|
532
|
-
|
|
533
|
-
#### received
|
|
534
|
-
|
|
535
|
-
`object`
|
|
536
|
-
|
|
537
|
-
The object to check.
|
|
538
|
-
|
|
539
|
-
#### expectedKeys
|
|
540
|
-
|
|
541
|
-
`string`[]
|
|
542
|
-
|
|
543
|
-
The keys that must all be present.
|
|
544
|
-
|
|
545
|
-
### Returns
|
|
546
|
-
|
|
547
|
-
[`ExpectationResult`](#../interfaces/ExpectationResult)
|
|
548
|
-
|
|
549
|
-
### toContainValues()
|
|
550
|
-
|
|
551
|
-
```ts
|
|
552
|
-
toContainValues(received, expectedValues): ExpectationResult;
|
|
553
|
-
```
|
|
554
|
-
|
|
555
|
-
Asserts that the received object contains all of the specified values (using deep equality).
|
|
556
|
-
|
|
557
|
-
### Parameters
|
|
558
|
-
|
|
559
|
-
#### received
|
|
560
|
-
|
|
561
|
-
`object`
|
|
562
|
-
|
|
563
|
-
The object to check.
|
|
564
|
-
|
|
565
|
-
#### expectedValues
|
|
566
|
-
|
|
567
|
-
`unknown`[]
|
|
568
|
-
|
|
569
|
-
The values that must all be present.
|
|
570
|
-
|
|
571
|
-
### Returns
|
|
572
|
-
|
|
573
|
-
[`ExpectationResult`](#../interfaces/ExpectationResult)
|
|
574
|
-
|
|
575
|
-
### toBeEmpty()
|
|
576
|
-
|
|
577
|
-
```ts
|
|
578
|
-
toBeEmpty(received): ExpectationResult;
|
|
579
|
-
```
|
|
580
|
-
|
|
581
|
-
Asserts the received value is empty (zero-length array/string, empty object, or empty Map/Set).
|
|
582
|
-
|
|
583
|
-
### Parameters
|
|
584
|
-
|
|
585
|
-
#### received
|
|
586
|
-
|
|
587
|
-
`unknown`
|
|
588
|
-
|
|
589
|
-
The value to check.
|
|
590
|
-
|
|
591
|
-
### Returns
|
|
592
|
-
|
|
593
|
-
[`ExpectationResult`](#../interfaces/ExpectationResult)
|
|
594
|
-
|
|
595
|
-
### toBeValidDate()
|
|
596
|
-
|
|
597
|
-
```ts
|
|
598
|
-
toBeValidDate(received): object;
|
|
599
|
-
```
|
|
600
|
-
|
|
601
|
-
Asserts the received value is a valid Date instance (not an invalid date).
|
|
602
|
-
|
|
603
|
-
### Parameters
|
|
604
|
-
|
|
605
|
-
#### received
|
|
606
|
-
|
|
607
|
-
`unknown`
|
|
608
|
-
|
|
609
|
-
The value to check.
|
|
610
|
-
|
|
611
|
-
### Returns
|
|
612
|
-
|
|
613
|
-
`object`
|
|
614
|
-
|
|
615
|
-
#### pass
|
|
616
|
-
|
|
617
|
-
```ts
|
|
618
|
-
pass: boolean = isValid;
|
|
619
|
-
```
|
|
620
|
-
|
|
621
|
-
#### message
|
|
622
|
-
|
|
623
|
-
```ts
|
|
624
|
-
message: () => string;
|
|
625
|
-
```
|
|
626
|
-
|
|
627
|
-
##### Returns
|
|
628
|
-
|
|
629
|
-
`string`
|
|
630
|
-
|
|
631
|
-
## Credits
|
|
632
|
-
|
|
633
|
-
[Made with 🔥 and ❄️ by XY Labs](https://xylabs.com)
|
|
634
|
-
|
|
635
|
-
[npm-badge]: https://img.shields.io/npm/v/@xylabs/vitest-matchers.svg
|
|
636
|
-
[npm-link]: https://www.npmjs.com/package/@xylabs/vitest-matchers
|
|
637
|
-
[license-badge]: https://img.shields.io/npm/l/@xylabs/vitest-matchers.svg
|
|
638
|
-
[license-link]: https://github.com/xylabs/sdk-js/blob/main/LICENSE
|
|
639
|
-
[logo]: https://cdn.xy.company/img/brand/XYPersistentCompany_Logo_Icon_Colored.svg
|
|
3
|
+
DEPRECATED — use `@ariestools/vitest-matchers` instead.
|
package/dist/neutral/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from '
|
|
1
|
+
export * from '@ariestools/vitest-matchers';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAA"}
|
package/dist/neutral/index.mjs
CHANGED
|
@@ -1,369 +1,3 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
|
|
3
|
-
if (typeof value === "string") return value;
|
|
4
|
-
if (typeof value === "number" && !Number.isFinite(value)) return String(value);
|
|
5
|
-
const json = JSON.stringify(value);
|
|
6
|
-
return json ?? String(value);
|
|
7
|
-
};
|
|
8
|
-
function toBeType(received, expectedType) {
|
|
9
|
-
const isPass = typeof received === expectedType && !Number.isNaN(received);
|
|
10
|
-
return isPass ? {
|
|
11
|
-
message: () => `expected ${formatValue(received)} not to be a ${expectedType}`,
|
|
12
|
-
pass: true
|
|
13
|
-
} : {
|
|
14
|
-
message: () => `expected ${formatValue(received)} to be a ${expectedType}`,
|
|
15
|
-
pass: false
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
var matchers = {
|
|
19
|
-
/**
|
|
20
|
-
* Asserts the received value is an array with the specified length.
|
|
21
|
-
* @param received - The value to check.
|
|
22
|
-
* @param expectedSize - The expected array length.
|
|
23
|
-
*/
|
|
24
|
-
toBeArrayOfSize(received, expectedSize) {
|
|
25
|
-
const isPass = Array.isArray(received) && received.length === expectedSize;
|
|
26
|
-
return isPass ? {
|
|
27
|
-
message: () => `expected array not to have size ${expectedSize}, but received array of size ${received.length}`,
|
|
28
|
-
pass: true
|
|
29
|
-
} : {
|
|
30
|
-
message: () => Array.isArray(received) ? `expected array of size ${expectedSize}, but received array of size ${received.length}` : `expected array of size ${expectedSize}, but received a non-array`,
|
|
31
|
-
pass: false
|
|
32
|
-
};
|
|
33
|
-
},
|
|
34
|
-
/**
|
|
35
|
-
* Asserts the received value is an array.
|
|
36
|
-
* @param received - The value to check.
|
|
37
|
-
*/
|
|
38
|
-
toBeArray(received) {
|
|
39
|
-
const isPass = Array.isArray(received);
|
|
40
|
-
return isPass ? {
|
|
41
|
-
message: () => "expected array",
|
|
42
|
-
pass: true
|
|
43
|
-
} : {
|
|
44
|
-
message: () => `expected array, but received ${typeof received}`,
|
|
45
|
-
pass: false
|
|
46
|
-
};
|
|
47
|
-
},
|
|
48
|
-
/**
|
|
49
|
-
* Asserts the received value is one of the values in the expected array.
|
|
50
|
-
* @param received - The value to check.
|
|
51
|
-
* @param expected - The array of acceptable values.
|
|
52
|
-
*/
|
|
53
|
-
toBeOneOf(received, expected) {
|
|
54
|
-
const isPass = expected.includes(received);
|
|
55
|
-
return isPass ? {
|
|
56
|
-
pass: true,
|
|
57
|
-
message: () => `expected ${formatValue(received)} not to be one of ${JSON.stringify(expected)}`
|
|
58
|
-
} : {
|
|
59
|
-
pass: false,
|
|
60
|
-
message: () => `expected ${formatValue(received)} to be one of ${JSON.stringify(expected)}`
|
|
61
|
-
};
|
|
62
|
-
},
|
|
63
|
-
/**
|
|
64
|
-
* Asserts the received number is negative (less than zero).
|
|
65
|
-
* @param received - The number to check.
|
|
66
|
-
*/
|
|
67
|
-
toBeNegative(received) {
|
|
68
|
-
if (typeof received !== "number") {
|
|
69
|
-
throw new TypeError(`Expected a number, but received ${typeof received}`);
|
|
70
|
-
}
|
|
71
|
-
const isPass = received < 0;
|
|
72
|
-
return isPass ? {
|
|
73
|
-
pass: true,
|
|
74
|
-
message: () => `expected ${received} not to be negative`
|
|
75
|
-
} : {
|
|
76
|
-
pass: false,
|
|
77
|
-
message: () => `expected ${received} to be negative`
|
|
78
|
-
};
|
|
79
|
-
},
|
|
80
|
-
/**
|
|
81
|
-
* Asserts the received number is positive (greater than zero).
|
|
82
|
-
* @param received - The number to check.
|
|
83
|
-
*/
|
|
84
|
-
toBePositive(received) {
|
|
85
|
-
if (typeof received !== "number") {
|
|
86
|
-
throw new TypeError(`Expected a number, but received ${typeof received}`);
|
|
87
|
-
}
|
|
88
|
-
const isPass = received > 0;
|
|
89
|
-
return isPass ? {
|
|
90
|
-
pass: true,
|
|
91
|
-
message: () => `expected ${received} not to be positive`
|
|
92
|
-
} : {
|
|
93
|
-
pass: false,
|
|
94
|
-
message: () => `expected ${received} to be positive`
|
|
95
|
-
};
|
|
96
|
-
},
|
|
97
|
-
/**
|
|
98
|
-
* Asserts the received value is of type `number` and not NaN.
|
|
99
|
-
* @param received - The value to check.
|
|
100
|
-
*/
|
|
101
|
-
toBeNumber: (received) => toBeType(received, "number"),
|
|
102
|
-
/**
|
|
103
|
-
* Asserts the received value is of type `function`.
|
|
104
|
-
* @param received - The value to check.
|
|
105
|
-
*/
|
|
106
|
-
toBeFunction: (received) => toBeType(received, "function"),
|
|
107
|
-
/**
|
|
108
|
-
* Asserts the received value is of type `string`.
|
|
109
|
-
* @param received - The value to check.
|
|
110
|
-
*/
|
|
111
|
-
toBeString: (received) => toBeType(received, "string"),
|
|
112
|
-
/**
|
|
113
|
-
* Asserts the received value is a plain object (not an array or null).
|
|
114
|
-
* @param received - The value to check.
|
|
115
|
-
*/
|
|
116
|
-
toBeObject(received) {
|
|
117
|
-
const isPass = typeof received === "object" && !Array.isArray(received) && received !== null;
|
|
118
|
-
return isPass ? {
|
|
119
|
-
message: () => `expected ${formatValue(received)} to be object`,
|
|
120
|
-
pass: true
|
|
121
|
-
} : {
|
|
122
|
-
message: () => `expected ${formatValue(received)} to be an object but was ${Array.isArray(received) ? "array" : typeof received}`,
|
|
123
|
-
pass: false
|
|
124
|
-
};
|
|
125
|
-
},
|
|
126
|
-
/**
|
|
127
|
-
* Asserts the received number is an integer.
|
|
128
|
-
* @param received - The number to check.
|
|
129
|
-
*/
|
|
130
|
-
toBeInteger(received) {
|
|
131
|
-
if (typeof received !== "number") {
|
|
132
|
-
throw new TypeError(`Expected a number, but received ${typeof received}`);
|
|
133
|
-
}
|
|
134
|
-
const isPass = Number.isSafeInteger(received);
|
|
135
|
-
return isPass ? {
|
|
136
|
-
pass: true,
|
|
137
|
-
message: () => `expected ${received} not to be an integer`
|
|
138
|
-
} : {
|
|
139
|
-
pass: false,
|
|
140
|
-
message: () => `expected ${received} to be an integer`
|
|
141
|
-
};
|
|
142
|
-
},
|
|
143
|
-
/**
|
|
144
|
-
* Asserts the received value is strictly `false`.
|
|
145
|
-
* @param received - The value to check.
|
|
146
|
-
*/
|
|
147
|
-
toBeFalse(received) {
|
|
148
|
-
const isPass = received === false;
|
|
149
|
-
return isPass ? {
|
|
150
|
-
message: () => `expected ${formatValue(received)} to be false`,
|
|
151
|
-
pass: true
|
|
152
|
-
} : {
|
|
153
|
-
message: () => `expected ${formatValue(received)} to be false but was not false`,
|
|
154
|
-
pass: false
|
|
155
|
-
};
|
|
156
|
-
},
|
|
157
|
-
/**
|
|
158
|
-
* Asserts the received value is strictly `true`.
|
|
159
|
-
* @param received - The value to check.
|
|
160
|
-
*/
|
|
161
|
-
toBeTrue(received) {
|
|
162
|
-
const isPass = received === true;
|
|
163
|
-
return isPass ? {
|
|
164
|
-
message: () => `expected ${formatValue(received)} to be true`,
|
|
165
|
-
pass: true
|
|
166
|
-
} : {
|
|
167
|
-
message: () => `expected ${formatValue(received)} to be true but was not true`,
|
|
168
|
-
pass: false
|
|
169
|
-
};
|
|
170
|
-
},
|
|
171
|
-
/**
|
|
172
|
-
* Asserts that all expected values are present in the received array or object values.
|
|
173
|
-
* @param received - The array or object to check.
|
|
174
|
-
* @param expectedValues - The values that must all be present.
|
|
175
|
-
*/
|
|
176
|
-
toContainAllValues(received, expectedValues) {
|
|
177
|
-
let receivedValues;
|
|
178
|
-
if (Array.isArray(received)) {
|
|
179
|
-
receivedValues = received;
|
|
180
|
-
} else if (typeof received === "object" && received !== null) {
|
|
181
|
-
receivedValues = Object.values(received);
|
|
182
|
-
} else {
|
|
183
|
-
return {
|
|
184
|
-
pass: false,
|
|
185
|
-
message: () => `Expected an array or object, but received ${typeof received}.`
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
const isPass = expectedValues.every((value) => receivedValues.includes(value));
|
|
189
|
-
return {
|
|
190
|
-
pass: isPass,
|
|
191
|
-
message: () => isPass ? `Expected ${JSON.stringify(received)} not to contain all values ${JSON.stringify(expectedValues)}, but it does.` : `Expected ${JSON.stringify(received)} to contain all values ${JSON.stringify(expectedValues)}, but it does not.`
|
|
192
|
-
};
|
|
193
|
-
},
|
|
194
|
-
/**
|
|
195
|
-
* Asserts that the received object contains the specified key.
|
|
196
|
-
* @param received - The object to check.
|
|
197
|
-
* @param key - The key that should be present.
|
|
198
|
-
*/
|
|
199
|
-
toContainKey(received, key) {
|
|
200
|
-
const isPass = Object.prototype.hasOwnProperty.call(received, key);
|
|
201
|
-
return isPass ? {
|
|
202
|
-
pass: true,
|
|
203
|
-
message: () => `Expected object not to contain key "${key}", but it does.`
|
|
204
|
-
} : {
|
|
205
|
-
pass: false,
|
|
206
|
-
message: () => `Expected object to contain key "${key}", but it does not.`
|
|
207
|
-
};
|
|
208
|
-
},
|
|
209
|
-
/**
|
|
210
|
-
* Asserts that the received array, string, or object values include the specified value.
|
|
211
|
-
* @param received - The array, string, or object to search within.
|
|
212
|
-
* @param value - The value to look for.
|
|
213
|
-
*/
|
|
214
|
-
toInclude(received, value) {
|
|
215
|
-
let isPass;
|
|
216
|
-
if (Array.isArray(received)) {
|
|
217
|
-
isPass = received.includes(value);
|
|
218
|
-
} else if (typeof received === "string") {
|
|
219
|
-
isPass = received.includes(String(value));
|
|
220
|
-
} else if (typeof received === "object" && received !== null) {
|
|
221
|
-
isPass = Object.values(received).includes(value);
|
|
222
|
-
} else {
|
|
223
|
-
isPass = false;
|
|
224
|
-
}
|
|
225
|
-
return {
|
|
226
|
-
pass: isPass,
|
|
227
|
-
message: () => isPass ? `Expected ${JSON.stringify(received)} not to include ${JSON.stringify(value)}, but it does.` : `Expected ${JSON.stringify(received)} to include ${JSON.stringify(value)}, but it does not.`
|
|
228
|
-
};
|
|
229
|
-
},
|
|
230
|
-
/**
|
|
231
|
-
* Asserts that the received array includes all members of the expected array.
|
|
232
|
-
* @param received - The array to check.
|
|
233
|
-
* @param expected - The members that must all be present.
|
|
234
|
-
*/
|
|
235
|
-
toIncludeAllMembers(received, expected) {
|
|
236
|
-
if (!Array.isArray(received) || !Array.isArray(expected)) {
|
|
237
|
-
return {
|
|
238
|
-
pass: false,
|
|
239
|
-
message: () => "Expected both received and expected values to be arrays."
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
const missingMembers = expected.filter((item) => !received.includes(item));
|
|
243
|
-
return missingMembers.length === 0 ? {
|
|
244
|
-
pass: true,
|
|
245
|
-
message: () => `Expected array not to include all members of ${JSON.stringify(expected)}, but it does.`
|
|
246
|
-
} : {
|
|
247
|
-
pass: false,
|
|
248
|
-
message: () => `Expected array to include all members of ${JSON.stringify(expected)}. Missing members: ${JSON.stringify(
|
|
249
|
-
missingMembers
|
|
250
|
-
)}.`
|
|
251
|
-
};
|
|
252
|
-
},
|
|
253
|
-
/**
|
|
254
|
-
* Asserts that the received object contains all of the specified keys.
|
|
255
|
-
* @param received - The object to check.
|
|
256
|
-
* @param expectedKeys - The keys that must all be present.
|
|
257
|
-
*/
|
|
258
|
-
toContainAllKeys(received, expectedKeys) {
|
|
259
|
-
if (typeof received !== "object" || received === null) {
|
|
260
|
-
return {
|
|
261
|
-
pass: false,
|
|
262
|
-
message: () => `Expected ${JSON.stringify(received)} to be an object.`
|
|
263
|
-
};
|
|
264
|
-
}
|
|
265
|
-
if (!Array.isArray(expectedKeys)) {
|
|
266
|
-
return {
|
|
267
|
-
pass: false,
|
|
268
|
-
message: () => `Expected keys to be an array, but received ${JSON.stringify(expectedKeys)}.`
|
|
269
|
-
};
|
|
270
|
-
}
|
|
271
|
-
const missingKeys = expectedKeys.filter((key) => !Object.hasOwn(received, key));
|
|
272
|
-
return missingKeys.length === 0 ? {
|
|
273
|
-
pass: true,
|
|
274
|
-
message: () => `Expected object not to contain all keys ${JSON.stringify(expectedKeys)}, but it does.`
|
|
275
|
-
} : {
|
|
276
|
-
pass: false,
|
|
277
|
-
message: () => `Expected object to contain all keys ${JSON.stringify(expectedKeys)}. Missing keys: ${JSON.stringify(
|
|
278
|
-
missingKeys
|
|
279
|
-
)}.`
|
|
280
|
-
};
|
|
281
|
-
},
|
|
282
|
-
/**
|
|
283
|
-
* Asserts that the received object contains all of the specified values (using deep equality).
|
|
284
|
-
* @param received - The object to check.
|
|
285
|
-
* @param expectedValues - The values that must all be present.
|
|
286
|
-
*/
|
|
287
|
-
toContainValues(received, expectedValues) {
|
|
288
|
-
if (typeof received !== "object" || received === null) {
|
|
289
|
-
return {
|
|
290
|
-
pass: false,
|
|
291
|
-
message: () => `Expected ${JSON.stringify(received)} to be an object.`
|
|
292
|
-
};
|
|
293
|
-
}
|
|
294
|
-
if (!Array.isArray(expectedValues)) {
|
|
295
|
-
return {
|
|
296
|
-
pass: false,
|
|
297
|
-
message: () => `Expected values to be an array, but received ${JSON.stringify(expectedValues)}.`
|
|
298
|
-
};
|
|
299
|
-
}
|
|
300
|
-
const objectValues = Object.values(received);
|
|
301
|
-
const deepEqual = (a, b) => {
|
|
302
|
-
if (a === b) return true;
|
|
303
|
-
if (typeof a !== typeof b) return false;
|
|
304
|
-
if (a !== null && b !== null && typeof a === "object" && typeof b === "object") {
|
|
305
|
-
const aKeys = Object.keys(a);
|
|
306
|
-
const bKeys = Object.keys(b);
|
|
307
|
-
if (aKeys.length !== bKeys.length) return false;
|
|
308
|
-
const aRecord = a;
|
|
309
|
-
const bRecord = b;
|
|
310
|
-
return aKeys.every((key) => deepEqual(aRecord[key], bRecord[key]));
|
|
311
|
-
}
|
|
312
|
-
return false;
|
|
313
|
-
};
|
|
314
|
-
const missingValues = expectedValues.filter(
|
|
315
|
-
(expectedValue) => objectValues.every((value) => !deepEqual(value, expectedValue))
|
|
316
|
-
);
|
|
317
|
-
return missingValues.length === 0 ? {
|
|
318
|
-
pass: true,
|
|
319
|
-
message: () => `Expected object not to contain all values ${JSON.stringify(expectedValues)}, but it does.`
|
|
320
|
-
} : {
|
|
321
|
-
pass: false,
|
|
322
|
-
message: () => `Expected object to contain all values ${JSON.stringify(expectedValues)}. Missing values: ${JSON.stringify(
|
|
323
|
-
missingValues
|
|
324
|
-
)}.`
|
|
325
|
-
};
|
|
326
|
-
},
|
|
327
|
-
/**
|
|
328
|
-
* Asserts the received value is empty (zero-length array/string, empty object, or empty Map/Set).
|
|
329
|
-
* @param received - The value to check.
|
|
330
|
-
*/
|
|
331
|
-
toBeEmpty(received) {
|
|
332
|
-
const isEmpty = (() => {
|
|
333
|
-
if (Array.isArray(received) || typeof received === "string") {
|
|
334
|
-
return received.length === 0;
|
|
335
|
-
}
|
|
336
|
-
if (received !== null && typeof received === "object") {
|
|
337
|
-
return Object.keys(received).length === 0;
|
|
338
|
-
}
|
|
339
|
-
})();
|
|
340
|
-
if (isEmpty === void 0) {
|
|
341
|
-
return {
|
|
342
|
-
pass: false,
|
|
343
|
-
message: () => `Expected value to be an empty array, string, object, Map, or Set, but received ${typeof received}.`
|
|
344
|
-
};
|
|
345
|
-
}
|
|
346
|
-
return isEmpty ? {
|
|
347
|
-
pass: true,
|
|
348
|
-
message: () => "Expected value not to be empty, but it was."
|
|
349
|
-
} : {
|
|
350
|
-
pass: false,
|
|
351
|
-
message: () => "Expected value to be empty, but it was not."
|
|
352
|
-
};
|
|
353
|
-
},
|
|
354
|
-
/**
|
|
355
|
-
* Asserts the received value is a valid Date instance (not an invalid date).
|
|
356
|
-
* @param received - The value to check.
|
|
357
|
-
*/
|
|
358
|
-
toBeValidDate(received) {
|
|
359
|
-
const isValid = received instanceof Date && !Number.isNaN(received.getTime());
|
|
360
|
-
return {
|
|
361
|
-
pass: isValid,
|
|
362
|
-
message: () => isValid ? `expected ${received.toISOString()} not to be a valid Date` : `expected ${formatValue(received)} to be a valid Date`
|
|
363
|
-
};
|
|
364
|
-
}
|
|
365
|
-
};
|
|
366
|
-
export {
|
|
367
|
-
matchers
|
|
368
|
-
};
|
|
1
|
+
// src/index.ts
|
|
2
|
+
export * from "@ariestools/vitest-matchers";
|
|
369
3
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/
|
|
4
|
-
"sourcesContent": ["/** Result returned by a custom matcher function. */\nexport interface ExpectationResult {\n /** The actual value received by the matcher. */\n actual?: unknown\n /** The expected value the matcher compared against. */\n expected?: unknown\n /** Returns a human-readable failure or negation message. */\n message: () => string\n /** Whether the matcher assertion passed. */\n pass: boolean\n}\n\nconst formatValue = (value: unknown): string => {\n if (typeof value === 'string') return value\n if (typeof value === 'number' && !Number.isFinite(value)) return String(value)\n const json = JSON.stringify(value)\n return json ?? String(value)\n}\n\n/**\n * Checks whether the received value matches the expected JavaScript type and is not NaN.\n * @param received - The value to check.\n * @param expectedType - The expected `typeof` string (e.g. 'number', 'string').\n * @returns An ExpectationResult indicating pass or fail.\n */\nfunction toBeType(received: unknown, expectedType: string): ExpectationResult {\n const isPass = typeof received === expectedType && !Number.isNaN(received)\n return isPass\n ? {\n message: () => `expected ${formatValue(received)} not to be a ${expectedType}`,\n pass: true,\n }\n : {\n message: () => `expected ${formatValue(received)} to be a ${expectedType}`,\n pass: false,\n }\n}\n\n/** Collection of custom Vitest matchers extending the built-in `expect` assertions. */\nexport const matchers = {\n /**\n * Asserts the received value is an array with the specified length.\n * @param received - The value to check.\n * @param expectedSize - The expected array length.\n */\n toBeArrayOfSize(received: unknown, expectedSize: number): ExpectationResult {\n const isPass = Array.isArray(received) && received.length === expectedSize\n return isPass\n ? {\n message: () => `expected array not to have size ${expectedSize}, but received array of size ${received.length}`,\n pass: true,\n }\n : {\n message: () => Array.isArray(received)\n ? `expected array of size ${expectedSize}, but received array of size ${received.length}`\n : `expected array of size ${expectedSize}, but received a non-array`,\n pass: false,\n }\n },\n /**\n * Asserts the received value is an array.\n * @param received - The value to check.\n */\n toBeArray(received: unknown): ExpectationResult {\n const isPass = Array.isArray(received)\n return isPass\n ? {\n message: () => 'expected array',\n pass: true,\n }\n : {\n message: () => `expected array, but received ${typeof received}`,\n pass: false,\n }\n },\n /**\n * Asserts the received value is one of the values in the expected array.\n * @param received - The value to check.\n * @param expected - The array of acceptable values.\n */\n toBeOneOf(received: unknown, expected: unknown[]): ExpectationResult {\n const isPass = expected.includes(received)\n return isPass\n ? {\n pass: true,\n message: () =>\n `expected ${formatValue(received)} not to be one of ${JSON.stringify(expected)}`,\n }\n : {\n pass: false,\n message: () =>\n `expected ${formatValue(received)} to be one of ${JSON.stringify(expected)}`,\n }\n },\n /**\n * Asserts the received number is negative (less than zero).\n * @param received - The number to check.\n */\n toBeNegative(received: number): ExpectationResult {\n if (typeof received !== 'number') {\n throw new TypeError(`Expected a number, but received ${typeof received}`)\n }\n\n const isPass = received < 0\n return isPass\n ? {\n pass: true,\n message: () =>\n `expected ${received} not to be negative`,\n }\n : {\n pass: false,\n message: () =>\n `expected ${received} to be negative`,\n }\n },\n /**\n * Asserts the received number is positive (greater than zero).\n * @param received - The number to check.\n */\n toBePositive(received: number): ExpectationResult {\n if (typeof received !== 'number') {\n throw new TypeError(`Expected a number, but received ${typeof received}`)\n }\n\n const isPass = received > 0\n return isPass\n ? {\n pass: true,\n message: () =>\n `expected ${received} not to be positive`,\n }\n : {\n pass: false,\n message: () =>\n `expected ${received} to be positive`,\n }\n },\n /**\n * Asserts the received value is of type `number` and not NaN.\n * @param received - The value to check.\n */\n toBeNumber: (received: unknown) => toBeType(received, 'number'),\n /**\n * Asserts the received value is of type `function`.\n * @param received - The value to check.\n */\n toBeFunction: (received: unknown) => toBeType(received, 'function'),\n /**\n * Asserts the received value is of type `string`.\n * @param received - The value to check.\n */\n toBeString: (received: unknown) => toBeType(received, 'string'),\n /**\n * Asserts the received value is a plain object (not an array or null).\n * @param received - The value to check.\n */\n toBeObject(received: unknown): ExpectationResult {\n const isPass = typeof received === 'object' && !Array.isArray(received) && received !== null\n return isPass\n ? {\n message: () => `expected ${formatValue(received)} to be object`,\n pass: true,\n }\n : {\n message: () => `expected ${formatValue(received)} to be an object but was ${Array.isArray(received) ? 'array' : typeof received}`,\n pass: false,\n }\n },\n /**\n * Asserts the received number is an integer.\n * @param received - The number to check.\n */\n toBeInteger(received: number): ExpectationResult {\n if (typeof received !== 'number') {\n throw new TypeError(`Expected a number, but received ${typeof received}`)\n }\n\n const isPass = Number.isSafeInteger(received)\n return isPass\n ? {\n pass: true,\n message: () =>\n `expected ${received} not to be an integer`,\n }\n : {\n pass: false,\n message: () =>\n `expected ${received} to be an integer`,\n }\n },\n /**\n * Asserts the received value is strictly `false`.\n * @param received - The value to check.\n */\n toBeFalse(received: unknown): ExpectationResult {\n const isPass = received === false\n return isPass\n ? {\n message: () => `expected ${formatValue(received)} to be false`,\n pass: true,\n }\n : {\n message: () => `expected ${formatValue(received)} to be false but was not false`,\n pass: false,\n }\n },\n /**\n * Asserts the received value is strictly `true`.\n * @param received - The value to check.\n */\n toBeTrue(received: unknown): ExpectationResult {\n const isPass = received === true\n return isPass\n ? {\n message: () => `expected ${formatValue(received)} to be true`,\n pass: true,\n }\n : {\n message: () => `expected ${formatValue(received)} to be true but was not true`,\n pass: false,\n }\n },\n /**\n * Asserts that all expected values are present in the received array or object values.\n * @param received - The array or object to check.\n * @param expectedValues - The values that must all be present.\n */\n toContainAllValues(received: unknown, expectedValues: unknown[]) {\n let receivedValues: unknown[]\n\n // Check if received is an array or an object\n if (Array.isArray(received)) {\n receivedValues = received\n } else if (typeof received === 'object' && received !== null) {\n receivedValues = Object.values(received)\n } else {\n return {\n pass: false,\n message: () => `Expected an array or object, but received ${typeof received}.`,\n }\n }\n\n // Check if all expected values are in the received values\n const isPass = expectedValues.every(value => receivedValues.includes(value))\n\n return {\n pass: isPass,\n message: () =>\n isPass\n ? `Expected ${JSON.stringify(received)} not to contain all values ${JSON.stringify(expectedValues)}, but it does.`\n : `Expected ${JSON.stringify(received)} to contain all values ${JSON.stringify(expectedValues)}, but it does not.`,\n }\n },\n /**\n * Asserts that the received object contains the specified key.\n * @param received - The object to check.\n * @param key - The key that should be present.\n */\n toContainKey(received: object, key: string) {\n const isPass = Object.prototype.hasOwnProperty.call(received, key)\n return isPass\n ? {\n pass: true,\n message: () => `Expected object not to contain key \"${key}\", but it does.`,\n }\n : {\n pass: false,\n message: () => `Expected object to contain key \"${key}\", but it does not.`,\n }\n },\n /**\n * Asserts that the received array, string, or object values include the specified value.\n * @param received - The array, string, or object to search within.\n * @param value - The value to look for.\n */\n toInclude(received: unknown, value: unknown) {\n let isPass: boolean\n\n if (Array.isArray(received)) {\n isPass = received.includes(value)\n } else if (typeof received === 'string') {\n isPass = received.includes(String(value))\n } else if (typeof received === 'object' && received !== null) {\n isPass = Object.values(received).includes(value)\n } else {\n isPass = false\n }\n\n return {\n pass: isPass,\n message: () =>\n isPass\n ? `Expected ${JSON.stringify(received)} not to include ${JSON.stringify(value)}, but it does.`\n : `Expected ${JSON.stringify(received)} to include ${JSON.stringify(value)}, but it does not.`,\n }\n },\n /**\n * Asserts that the received array includes all members of the expected array.\n * @param received - The array to check.\n * @param expected - The members that must all be present.\n */\n toIncludeAllMembers(received: unknown[], expected: unknown[]): ExpectationResult {\n if (!Array.isArray(received) || !Array.isArray(expected)) {\n return {\n pass: false,\n message: () => 'Expected both received and expected values to be arrays.',\n }\n }\n\n const missingMembers = expected.filter(item => !received.includes(item))\n\n return missingMembers.length === 0\n ? {\n pass: true,\n message: () =>\n `Expected array not to include all members of ${JSON.stringify(expected)}, but it does.`,\n }\n : {\n pass: false,\n message: () =>\n `Expected array to include all members of ${JSON.stringify(expected)}. Missing members: ${JSON.stringify(\n missingMembers,\n )}.`,\n }\n },\n /**\n * Asserts that the received object contains all of the specified keys.\n * @param received - The object to check.\n * @param expectedKeys - The keys that must all be present.\n */\n toContainAllKeys(received: object, expectedKeys: string[]): ExpectationResult {\n if (typeof received !== 'object' || received === null) {\n return {\n pass: false,\n message: () => `Expected ${JSON.stringify(received)} to be an object.`,\n }\n }\n\n if (!Array.isArray(expectedKeys)) {\n return {\n pass: false,\n message: () => `Expected keys to be an array, but received ${JSON.stringify(expectedKeys)}.`,\n }\n }\n\n const missingKeys = expectedKeys.filter(key => !Object.hasOwn(received, key))\n\n return missingKeys.length === 0\n ? {\n pass: true,\n message: () =>\n `Expected object not to contain all keys ${JSON.stringify(expectedKeys)}, but it does.`,\n }\n : {\n pass: false,\n message: () =>\n `Expected object to contain all keys ${JSON.stringify(expectedKeys)}. Missing keys: ${JSON.stringify(\n missingKeys,\n )}.`,\n }\n },\n /**\n * Asserts that the received object contains all of the specified values (using deep equality).\n * @param received - The object to check.\n * @param expectedValues - The values that must all be present.\n */\n toContainValues(received: object, expectedValues: unknown[]): ExpectationResult {\n if (typeof received !== 'object' || received === null) {\n return {\n pass: false,\n message: () => `Expected ${JSON.stringify(received)} to be an object.`,\n }\n }\n\n if (!Array.isArray(expectedValues)) {\n return {\n pass: false,\n message: () => `Expected values to be an array, but received ${JSON.stringify(expectedValues)}.`,\n }\n }\n\n const objectValues = Object.values(received)\n\n const deepEqual = (a: unknown, b: unknown): boolean => {\n if (a === b) return true\n if (typeof a !== typeof b) return false\n if (a !== null && b !== null && typeof a === 'object' && typeof b === 'object') {\n const aKeys = Object.keys(a)\n const bKeys = Object.keys(b)\n if (aKeys.length !== bKeys.length) return false\n const aRecord = a as Record<string, unknown>\n const bRecord = b as Record<string, unknown>\n return aKeys.every(key => deepEqual(aRecord[key], bRecord[key]))\n }\n return false\n }\n\n const missingValues = expectedValues.filter(\n expectedValue => objectValues.every(value => !deepEqual(value, expectedValue)),\n )\n\n return missingValues.length === 0\n ? {\n pass: true,\n message: () =>\n `Expected object not to contain all values ${JSON.stringify(expectedValues)}, but it does.`,\n }\n : {\n pass: false,\n message: () =>\n `Expected object to contain all values ${JSON.stringify(expectedValues)}. Missing values: ${JSON.stringify(\n missingValues,\n )}.`,\n }\n },\n /**\n * Asserts the received value is empty (zero-length array/string, empty object, or empty Map/Set).\n * @param received - The value to check.\n */\n toBeEmpty(received: unknown): ExpectationResult {\n const isEmpty = (() => {\n if (Array.isArray(received) || typeof received === 'string') {\n return received.length === 0\n }\n if (received !== null && typeof received === 'object') {\n return Object.keys(received).length === 0\n }\n })()\n\n if (isEmpty === undefined) {\n return {\n pass: false,\n message: () =>\n `Expected value to be an empty array, string, object, Map, or Set, but received ${typeof received}.`,\n }\n }\n\n return isEmpty\n ? {\n pass: true,\n message: () =>\n 'Expected value not to be empty, but it was.',\n }\n : {\n pass: false,\n message: () =>\n 'Expected value to be empty, but it was not.',\n }\n },\n /**\n * Asserts the received value is a valid Date instance (not an invalid date).\n * @param received - The value to check.\n */\n toBeValidDate(\n received: unknown,\n ) {\n const isValid\n = received instanceof Date && !Number.isNaN(received.getTime())\n\n return {\n pass: isValid,\n message: () =>\n isValid\n ? `expected ${received.toISOString()} not to be a valid Date`\n : `expected ${formatValue(received)} to be a valid Date`,\n }\n },\n}\n"],
|
|
5
|
-
"mappings": ";
|
|
3
|
+
"sources": ["../../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["export * from '@ariestools/vitest-matchers'\n"],
|
|
5
|
+
"mappings": ";AAAA,cAAc;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/neutral/model.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from '@ariestools/vitest-matchers/model';
|
|
2
2
|
//# sourceMappingURL=model.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/model.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/model.ts"],"names":[],"mappings":"AAAA,cAAc,mCAAmC,CAAA"}
|
package/dist/neutral/model.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xylabs/vitest-matchers",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "8.0.0",
|
|
4
|
+
"description": "DEPRECATED — use @ariestools/vitest-matchers. Backward-compatibility re-export shim.",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"log",
|
|
7
|
-
"logger",
|
|
8
|
-
"logging",
|
|
9
6
|
"xylabs",
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"esm"
|
|
7
|
+
"deprecated",
|
|
8
|
+
"shim"
|
|
13
9
|
],
|
|
14
10
|
"homepage": "https://xylabs.com",
|
|
15
11
|
"bugs": {
|
|
@@ -46,20 +42,22 @@
|
|
|
46
42
|
"!**/*.test.*",
|
|
47
43
|
"README.md"
|
|
48
44
|
],
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@ariestools/vitest-matchers": "~8.0.0"
|
|
47
|
+
},
|
|
49
48
|
"devDependencies": {
|
|
50
49
|
"@xylabs/toolchain": "~8.6.2",
|
|
51
50
|
"@xylabs/tsconfig": "~8.6.2",
|
|
52
51
|
"browserslist": "~4.28.4",
|
|
53
52
|
"eslint": "~10.6.0",
|
|
54
53
|
"eslint-import-resolver-typescript": "~4.4.5",
|
|
55
|
-
"typescript": "~6.0.3"
|
|
56
|
-
"vite": "~8.1.3",
|
|
57
|
-
"vitest": "~4.1.9"
|
|
54
|
+
"typescript": "~6.0.3"
|
|
58
55
|
},
|
|
59
56
|
"engines": {
|
|
60
57
|
"node": ">=18"
|
|
61
58
|
},
|
|
62
59
|
"publishConfig": {
|
|
63
60
|
"access": "public"
|
|
64
|
-
}
|
|
61
|
+
},
|
|
62
|
+
"deprecated": "Use @ariestools/vitest-matchers instead. @xylabs/vitest-matchers is a compatibility shim only and will not receive further updates."
|
|
65
63
|
}
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
/** Result returned by a custom matcher function. */
|
|
2
|
-
export interface ExpectationResult {
|
|
3
|
-
/** The actual value received by the matcher. */
|
|
4
|
-
actual?: unknown;
|
|
5
|
-
/** The expected value the matcher compared against. */
|
|
6
|
-
expected?: unknown;
|
|
7
|
-
/** Returns a human-readable failure or negation message. */
|
|
8
|
-
message: () => string;
|
|
9
|
-
/** Whether the matcher assertion passed. */
|
|
10
|
-
pass: boolean;
|
|
11
|
-
}
|
|
12
|
-
/** Collection of custom Vitest matchers extending the built-in `expect` assertions. */
|
|
13
|
-
export declare const matchers: {
|
|
14
|
-
/**
|
|
15
|
-
* Asserts the received value is an array with the specified length.
|
|
16
|
-
* @param received - The value to check.
|
|
17
|
-
* @param expectedSize - The expected array length.
|
|
18
|
-
*/
|
|
19
|
-
toBeArrayOfSize(received: unknown, expectedSize: number): ExpectationResult;
|
|
20
|
-
/**
|
|
21
|
-
* Asserts the received value is an array.
|
|
22
|
-
* @param received - The value to check.
|
|
23
|
-
*/
|
|
24
|
-
toBeArray(received: unknown): ExpectationResult;
|
|
25
|
-
/**
|
|
26
|
-
* Asserts the received value is one of the values in the expected array.
|
|
27
|
-
* @param received - The value to check.
|
|
28
|
-
* @param expected - The array of acceptable values.
|
|
29
|
-
*/
|
|
30
|
-
toBeOneOf(received: unknown, expected: unknown[]): ExpectationResult;
|
|
31
|
-
/**
|
|
32
|
-
* Asserts the received number is negative (less than zero).
|
|
33
|
-
* @param received - The number to check.
|
|
34
|
-
*/
|
|
35
|
-
toBeNegative(received: number): ExpectationResult;
|
|
36
|
-
/**
|
|
37
|
-
* Asserts the received number is positive (greater than zero).
|
|
38
|
-
* @param received - The number to check.
|
|
39
|
-
*/
|
|
40
|
-
toBePositive(received: number): ExpectationResult;
|
|
41
|
-
/**
|
|
42
|
-
* Asserts the received value is of type `number` and not NaN.
|
|
43
|
-
* @param received - The value to check.
|
|
44
|
-
*/
|
|
45
|
-
toBeNumber: (received: unknown) => ExpectationResult;
|
|
46
|
-
/**
|
|
47
|
-
* Asserts the received value is of type `function`.
|
|
48
|
-
* @param received - The value to check.
|
|
49
|
-
*/
|
|
50
|
-
toBeFunction: (received: unknown) => ExpectationResult;
|
|
51
|
-
/**
|
|
52
|
-
* Asserts the received value is of type `string`.
|
|
53
|
-
* @param received - The value to check.
|
|
54
|
-
*/
|
|
55
|
-
toBeString: (received: unknown) => ExpectationResult;
|
|
56
|
-
/**
|
|
57
|
-
* Asserts the received value is a plain object (not an array or null).
|
|
58
|
-
* @param received - The value to check.
|
|
59
|
-
*/
|
|
60
|
-
toBeObject(received: unknown): ExpectationResult;
|
|
61
|
-
/**
|
|
62
|
-
* Asserts the received number is an integer.
|
|
63
|
-
* @param received - The number to check.
|
|
64
|
-
*/
|
|
65
|
-
toBeInteger(received: number): ExpectationResult;
|
|
66
|
-
/**
|
|
67
|
-
* Asserts the received value is strictly `false`.
|
|
68
|
-
* @param received - The value to check.
|
|
69
|
-
*/
|
|
70
|
-
toBeFalse(received: unknown): ExpectationResult;
|
|
71
|
-
/**
|
|
72
|
-
* Asserts the received value is strictly `true`.
|
|
73
|
-
* @param received - The value to check.
|
|
74
|
-
*/
|
|
75
|
-
toBeTrue(received: unknown): ExpectationResult;
|
|
76
|
-
/**
|
|
77
|
-
* Asserts that all expected values are present in the received array or object values.
|
|
78
|
-
* @param received - The array or object to check.
|
|
79
|
-
* @param expectedValues - The values that must all be present.
|
|
80
|
-
*/
|
|
81
|
-
toContainAllValues(received: unknown, expectedValues: unknown[]): {
|
|
82
|
-
pass: boolean;
|
|
83
|
-
message: () => string;
|
|
84
|
-
};
|
|
85
|
-
/**
|
|
86
|
-
* Asserts that the received object contains the specified key.
|
|
87
|
-
* @param received - The object to check.
|
|
88
|
-
* @param key - The key that should be present.
|
|
89
|
-
*/
|
|
90
|
-
toContainKey(received: object, key: string): {
|
|
91
|
-
pass: boolean;
|
|
92
|
-
message: () => string;
|
|
93
|
-
};
|
|
94
|
-
/**
|
|
95
|
-
* Asserts that the received array, string, or object values include the specified value.
|
|
96
|
-
* @param received - The array, string, or object to search within.
|
|
97
|
-
* @param value - The value to look for.
|
|
98
|
-
*/
|
|
99
|
-
toInclude(received: unknown, value: unknown): {
|
|
100
|
-
pass: boolean;
|
|
101
|
-
message: () => string;
|
|
102
|
-
};
|
|
103
|
-
/**
|
|
104
|
-
* Asserts that the received array includes all members of the expected array.
|
|
105
|
-
* @param received - The array to check.
|
|
106
|
-
* @param expected - The members that must all be present.
|
|
107
|
-
*/
|
|
108
|
-
toIncludeAllMembers(received: unknown[], expected: unknown[]): ExpectationResult;
|
|
109
|
-
/**
|
|
110
|
-
* Asserts that the received object contains all of the specified keys.
|
|
111
|
-
* @param received - The object to check.
|
|
112
|
-
* @param expectedKeys - The keys that must all be present.
|
|
113
|
-
*/
|
|
114
|
-
toContainAllKeys(received: object, expectedKeys: string[]): ExpectationResult;
|
|
115
|
-
/**
|
|
116
|
-
* Asserts that the received object contains all of the specified values (using deep equality).
|
|
117
|
-
* @param received - The object to check.
|
|
118
|
-
* @param expectedValues - The values that must all be present.
|
|
119
|
-
*/
|
|
120
|
-
toContainValues(received: object, expectedValues: unknown[]): ExpectationResult;
|
|
121
|
-
/**
|
|
122
|
-
* Asserts the received value is empty (zero-length array/string, empty object, or empty Map/Set).
|
|
123
|
-
* @param received - The value to check.
|
|
124
|
-
*/
|
|
125
|
-
toBeEmpty(received: unknown): ExpectationResult;
|
|
126
|
-
/**
|
|
127
|
-
* Asserts the received value is a valid Date instance (not an invalid date).
|
|
128
|
-
* @param received - The value to check.
|
|
129
|
-
*/
|
|
130
|
-
toBeValidDate(received: unknown): {
|
|
131
|
-
pass: boolean;
|
|
132
|
-
message: () => string;
|
|
133
|
-
};
|
|
134
|
-
};
|
|
135
|
-
//# sourceMappingURL=customMatchers.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"customMatchers.d.ts","sourceRoot":"","sources":["../../src/customMatchers.ts"],"names":[],"mappings":"AAAA,oDAAoD;AACpD,MAAM,WAAW,iBAAiB;IAChC,gDAAgD;IAChD,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,uDAAuD;IACvD,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,4DAA4D;IAC5D,OAAO,EAAE,MAAM,MAAM,CAAA;IACrB,4CAA4C;IAC5C,IAAI,EAAE,OAAO,CAAA;CACd;AA4BD,uFAAuF;AACvF,eAAO,MAAM,QAAQ;IACnB;;;;OAIG;8BACuB,OAAO,gBAAgB,MAAM,GAAG,iBAAiB;IAc3E;;;OAGG;wBACiB,OAAO,GAAG,iBAAiB;IAY/C;;;;OAIG;wBACiB,OAAO,YAAY,OAAO,EAAE,GAAG,iBAAiB;IAcpE;;;OAGG;2BACoB,MAAM,GAAG,iBAAiB;IAkBjD;;;OAGG;2BACoB,MAAM,GAAG,iBAAiB;IAkBjD;;;OAGG;2BACoB,OAAO;IAC9B;;;OAGG;6BACsB,OAAO;IAChC;;;OAGG;2BACoB,OAAO;IAC9B;;;OAGG;yBACkB,OAAO,GAAG,iBAAiB;IAYhD;;;OAGG;0BACmB,MAAM,GAAG,iBAAiB;IAkBhD;;;OAGG;wBACiB,OAAO,GAAG,iBAAiB;IAY/C;;;OAGG;uBACgB,OAAO,GAAG,iBAAiB;IAY9C;;;;OAIG;iCAC0B,OAAO,kBAAkB,OAAO,EAAE;;;;IA0B/D;;;;OAIG;2BACoB,MAAM,OAAO,MAAM;;;;IAY1C;;;;OAIG;wBACiB,OAAO,SAAS,OAAO;;;;IAqB3C;;;;OAIG;kCAC2B,OAAO,EAAE,YAAY,OAAO,EAAE,GAAG,iBAAiB;IAwBhF;;;;OAIG;+BACwB,MAAM,gBAAgB,MAAM,EAAE,GAAG,iBAAiB;IA+B7E;;;;OAIG;8BACuB,MAAM,kBAAkB,OAAO,EAAE,GAAG,iBAAiB;IAiD/E;;;OAGG;wBACiB,OAAO,GAAG,iBAAiB;IA8B/C;;;OAGG;4BAES,OAAO;;;;CAapB,CAAA"}
|