rescript-vitest-extras 0.1.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.
@@ -0,0 +1,455 @@
1
+ // VitestExtras__MockExpect.res - Expect matchers for mock functions
2
+ //
3
+ // These matchers work with Vitest's expect() function for asserting on mock behavior.
4
+ // Provides arity-specific variants for type-safe argument checking.
5
+
6
+ open Vitest_Types
7
+
8
+ // =============================================================================
9
+ // Base Mock Matchers (no argument checking)
10
+ // =============================================================================
11
+
12
+ /** Asserts that the mock function was called at least once */
13
+ @send external toHaveBeenCalled: assertion<'mock> => unit = "toHaveBeenCalled"
14
+
15
+ /** Asserts that the mock function was called exactly once */
16
+ @send external toHaveBeenCalledOnce: assertion<'mock> => unit = "toHaveBeenCalledOnce"
17
+
18
+ /** Alias for toHaveBeenCalled */
19
+ @send external toBeCalled: assertion<'mock> => unit = "toBeCalled"
20
+
21
+ /** Asserts that the mock function was called exactly n times */
22
+ @send external toHaveBeenCalledTimes: (assertion<'mock>, int) => unit = "toHaveBeenCalledTimes"
23
+
24
+ /** Alias for toHaveBeenCalledTimes */
25
+ @send external toBeCalledTimes: (assertion<'mock>, int) => unit = "toBeCalledTimes"
26
+
27
+ // =============================================================================
28
+ // toHaveBeenCalledWith - Arity Variants
29
+ // =============================================================================
30
+
31
+ /** Asserts the mock was called with no arguments */
32
+ @send external toHaveBeenCalledWith0: assertion<VitestExtras__Mock.mockFn0<'ret>> => unit =
33
+ "toHaveBeenCalledWith"
34
+
35
+ /** Asserts the mock was called with 1 argument */
36
+ @send
37
+ external toHaveBeenCalledWith1: (assertion<VitestExtras__Mock.mockFn1<'a, 'ret>>, 'a) => unit =
38
+ "toHaveBeenCalledWith"
39
+
40
+ /** Asserts the mock was called with 2 arguments */
41
+ @send
42
+ external toHaveBeenCalledWith2: (
43
+ assertion<VitestExtras__Mock.mockFn2<'a, 'b, 'ret>>,
44
+ 'a,
45
+ 'b,
46
+ ) => unit = "toHaveBeenCalledWith"
47
+
48
+ /** Asserts the mock was called with 3 arguments */
49
+ @send
50
+ external toHaveBeenCalledWith3: (
51
+ assertion<VitestExtras__Mock.mockFn3<'a, 'b, 'c, 'ret>>,
52
+ 'a,
53
+ 'b,
54
+ 'c,
55
+ ) => unit = "toHaveBeenCalledWith"
56
+
57
+ /** Asserts the mock was called with 4 arguments */
58
+ @send
59
+ external toHaveBeenCalledWith4: (
60
+ assertion<VitestExtras__Mock.mockFn4<'a, 'b, 'c, 'd, 'ret>>,
61
+ 'a,
62
+ 'b,
63
+ 'c,
64
+ 'd,
65
+ ) => unit = "toHaveBeenCalledWith"
66
+
67
+ /** Asserts the mock was called with 5 arguments */
68
+ @send
69
+ external toHaveBeenCalledWith5: (
70
+ assertion<VitestExtras__Mock.mockFn5<'a, 'b, 'c, 'd, 'e, 'ret>>,
71
+ 'a,
72
+ 'b,
73
+ 'c,
74
+ 'd,
75
+ 'e,
76
+ ) => unit = "toHaveBeenCalledWith"
77
+
78
+ // Aliases
79
+ @send
80
+ external toBeCalledWith0: assertion<VitestExtras__Mock.mockFn0<'ret>> => unit = "toBeCalledWith"
81
+
82
+ @send
83
+ external toBeCalledWith1: (assertion<VitestExtras__Mock.mockFn1<'a, 'ret>>, 'a) => unit =
84
+ "toBeCalledWith"
85
+
86
+ @send
87
+ external toBeCalledWith2: (assertion<VitestExtras__Mock.mockFn2<'a, 'b, 'ret>>, 'a, 'b) => unit =
88
+ "toBeCalledWith"
89
+
90
+ @send
91
+ external toBeCalledWith3: (
92
+ assertion<VitestExtras__Mock.mockFn3<'a, 'b, 'c, 'ret>>,
93
+ 'a,
94
+ 'b,
95
+ 'c,
96
+ ) => unit = "toBeCalledWith"
97
+
98
+ @send
99
+ external toBeCalledWith4: (
100
+ assertion<VitestExtras__Mock.mockFn4<'a, 'b, 'c, 'd, 'ret>>,
101
+ 'a,
102
+ 'b,
103
+ 'c,
104
+ 'd,
105
+ ) => unit = "toBeCalledWith"
106
+
107
+ @send
108
+ external toBeCalledWith5: (
109
+ assertion<VitestExtras__Mock.mockFn5<'a, 'b, 'c, 'd, 'e, 'ret>>,
110
+ 'a,
111
+ 'b,
112
+ 'c,
113
+ 'd,
114
+ 'e,
115
+ ) => unit = "toBeCalledWith"
116
+
117
+ // =============================================================================
118
+ // toHaveBeenCalledExactlyOnceWith - Arity Variants
119
+ // =============================================================================
120
+
121
+ /** Asserts the mock was called exactly once with no arguments */
122
+ @send
123
+ external toHaveBeenCalledExactlyOnceWith0: assertion<VitestExtras__Mock.mockFn0<'ret>> => unit =
124
+ "toHaveBeenCalledExactlyOnceWith"
125
+
126
+ /** Asserts the mock was called exactly once with 1 argument */
127
+ @send
128
+ external toHaveBeenCalledExactlyOnceWith1: (
129
+ assertion<VitestExtras__Mock.mockFn1<'a, 'ret>>,
130
+ 'a,
131
+ ) => unit = "toHaveBeenCalledExactlyOnceWith"
132
+
133
+ /** Asserts the mock was called exactly once with 2 arguments */
134
+ @send
135
+ external toHaveBeenCalledExactlyOnceWith2: (
136
+ assertion<VitestExtras__Mock.mockFn2<'a, 'b, 'ret>>,
137
+ 'a,
138
+ 'b,
139
+ ) => unit = "toHaveBeenCalledExactlyOnceWith"
140
+
141
+ /** Asserts the mock was called exactly once with 3 arguments */
142
+ @send
143
+ external toHaveBeenCalledExactlyOnceWith3: (
144
+ assertion<VitestExtras__Mock.mockFn3<'a, 'b, 'c, 'ret>>,
145
+ 'a,
146
+ 'b,
147
+ 'c,
148
+ ) => unit = "toHaveBeenCalledExactlyOnceWith"
149
+
150
+ /** Asserts the mock was called exactly once with 4 arguments */
151
+ @send
152
+ external toHaveBeenCalledExactlyOnceWith4: (
153
+ assertion<VitestExtras__Mock.mockFn4<'a, 'b, 'c, 'd, 'ret>>,
154
+ 'a,
155
+ 'b,
156
+ 'c,
157
+ 'd,
158
+ ) => unit = "toHaveBeenCalledExactlyOnceWith"
159
+
160
+ /** Asserts the mock was called exactly once with 5 arguments */
161
+ @send
162
+ external toHaveBeenCalledExactlyOnceWith5: (
163
+ assertion<VitestExtras__Mock.mockFn5<'a, 'b, 'c, 'd, 'e, 'ret>>,
164
+ 'a,
165
+ 'b,
166
+ 'c,
167
+ 'd,
168
+ 'e,
169
+ ) => unit = "toHaveBeenCalledExactlyOnceWith"
170
+
171
+ // =============================================================================
172
+ // toHaveBeenLastCalledWith - Arity Variants
173
+ // =============================================================================
174
+
175
+ /** Asserts the mock's last call had no arguments */
176
+ @send
177
+ external toHaveBeenLastCalledWith0: assertion<VitestExtras__Mock.mockFn0<'ret>> => unit =
178
+ "toHaveBeenLastCalledWith"
179
+
180
+ /** Asserts the mock's last call had 1 argument */
181
+ @send
182
+ external toHaveBeenLastCalledWith1: (assertion<VitestExtras__Mock.mockFn1<'a, 'ret>>, 'a) => unit =
183
+ "toHaveBeenLastCalledWith"
184
+
185
+ /** Asserts the mock's last call had 2 arguments */
186
+ @send
187
+ external toHaveBeenLastCalledWith2: (
188
+ assertion<VitestExtras__Mock.mockFn2<'a, 'b, 'ret>>,
189
+ 'a,
190
+ 'b,
191
+ ) => unit = "toHaveBeenLastCalledWith"
192
+
193
+ /** Asserts the mock's last call had 3 arguments */
194
+ @send
195
+ external toHaveBeenLastCalledWith3: (
196
+ assertion<VitestExtras__Mock.mockFn3<'a, 'b, 'c, 'ret>>,
197
+ 'a,
198
+ 'b,
199
+ 'c,
200
+ ) => unit = "toHaveBeenLastCalledWith"
201
+
202
+ /** Asserts the mock's last call had 4 arguments */
203
+ @send
204
+ external toHaveBeenLastCalledWith4: (
205
+ assertion<VitestExtras__Mock.mockFn4<'a, 'b, 'c, 'd, 'ret>>,
206
+ 'a,
207
+ 'b,
208
+ 'c,
209
+ 'd,
210
+ ) => unit = "toHaveBeenLastCalledWith"
211
+
212
+ /** Asserts the mock's last call had 5 arguments */
213
+ @send
214
+ external toHaveBeenLastCalledWith5: (
215
+ assertion<VitestExtras__Mock.mockFn5<'a, 'b, 'c, 'd, 'e, 'ret>>,
216
+ 'a,
217
+ 'b,
218
+ 'c,
219
+ 'd,
220
+ 'e,
221
+ ) => unit = "toHaveBeenLastCalledWith"
222
+
223
+ // Aliases
224
+ @send
225
+ external lastCalledWith0: assertion<VitestExtras__Mock.mockFn0<'ret>> => unit = "lastCalledWith"
226
+
227
+ @send
228
+ external lastCalledWith1: (assertion<VitestExtras__Mock.mockFn1<'a, 'ret>>, 'a) => unit =
229
+ "lastCalledWith"
230
+
231
+ @send
232
+ external lastCalledWith2: (assertion<VitestExtras__Mock.mockFn2<'a, 'b, 'ret>>, 'a, 'b) => unit =
233
+ "lastCalledWith"
234
+
235
+ @send
236
+ external lastCalledWith3: (
237
+ assertion<VitestExtras__Mock.mockFn3<'a, 'b, 'c, 'ret>>,
238
+ 'a,
239
+ 'b,
240
+ 'c,
241
+ ) => unit = "lastCalledWith"
242
+
243
+ @send
244
+ external lastCalledWith4: (
245
+ assertion<VitestExtras__Mock.mockFn4<'a, 'b, 'c, 'd, 'ret>>,
246
+ 'a,
247
+ 'b,
248
+ 'c,
249
+ 'd,
250
+ ) => unit = "lastCalledWith"
251
+
252
+ @send
253
+ external lastCalledWith5: (
254
+ assertion<VitestExtras__Mock.mockFn5<'a, 'b, 'c, 'd, 'e, 'ret>>,
255
+ 'a,
256
+ 'b,
257
+ 'c,
258
+ 'd,
259
+ 'e,
260
+ ) => unit = "lastCalledWith"
261
+
262
+ // =============================================================================
263
+ // toHaveBeenNthCalledWith - Arity Variants
264
+ // =============================================================================
265
+
266
+ /** Asserts the nth call had no arguments */
267
+ @send
268
+ external toHaveBeenNthCalledWith0: (assertion<VitestExtras__Mock.mockFn0<'ret>>, int) => unit =
269
+ "toHaveBeenNthCalledWith"
270
+
271
+ /** Asserts the nth call had 1 argument */
272
+ @send
273
+ external toHaveBeenNthCalledWith1: (
274
+ assertion<VitestExtras__Mock.mockFn1<'a, 'ret>>,
275
+ int,
276
+ 'a,
277
+ ) => unit = "toHaveBeenNthCalledWith"
278
+
279
+ /** Asserts the nth call had 2 arguments */
280
+ @send
281
+ external toHaveBeenNthCalledWith2: (
282
+ assertion<VitestExtras__Mock.mockFn2<'a, 'b, 'ret>>,
283
+ int,
284
+ 'a,
285
+ 'b,
286
+ ) => unit = "toHaveBeenNthCalledWith"
287
+
288
+ /** Asserts the nth call had 3 arguments */
289
+ @send
290
+ external toHaveBeenNthCalledWith3: (
291
+ assertion<VitestExtras__Mock.mockFn3<'a, 'b, 'c, 'ret>>,
292
+ int,
293
+ 'a,
294
+ 'b,
295
+ 'c,
296
+ ) => unit = "toHaveBeenNthCalledWith"
297
+
298
+ /** Asserts the nth call had 4 arguments */
299
+ @send
300
+ external toHaveBeenNthCalledWith4: (
301
+ assertion<VitestExtras__Mock.mockFn4<'a, 'b, 'c, 'd, 'ret>>,
302
+ int,
303
+ 'a,
304
+ 'b,
305
+ 'c,
306
+ 'd,
307
+ ) => unit = "toHaveBeenNthCalledWith"
308
+
309
+ /** Asserts the nth call had 5 arguments */
310
+ @send
311
+ external toHaveBeenNthCalledWith5: (
312
+ assertion<VitestExtras__Mock.mockFn5<'a, 'b, 'c, 'd, 'e, 'ret>>,
313
+ int,
314
+ 'a,
315
+ 'b,
316
+ 'c,
317
+ 'd,
318
+ 'e,
319
+ ) => unit = "toHaveBeenNthCalledWith"
320
+
321
+ // Aliases
322
+ @send
323
+ external nthCalledWith0: (assertion<VitestExtras__Mock.mockFn0<'ret>>, int) => unit =
324
+ "nthCalledWith"
325
+
326
+ @send
327
+ external nthCalledWith1: (assertion<VitestExtras__Mock.mockFn1<'a, 'ret>>, int, 'a) => unit =
328
+ "nthCalledWith"
329
+
330
+ @send
331
+ external nthCalledWith2: (
332
+ assertion<VitestExtras__Mock.mockFn2<'a, 'b, 'ret>>,
333
+ int,
334
+ 'a,
335
+ 'b,
336
+ ) => unit = "nthCalledWith"
337
+
338
+ @send
339
+ external nthCalledWith3: (
340
+ assertion<VitestExtras__Mock.mockFn3<'a, 'b, 'c, 'ret>>,
341
+ int,
342
+ 'a,
343
+ 'b,
344
+ 'c,
345
+ ) => unit = "nthCalledWith"
346
+
347
+ @send
348
+ external nthCalledWith4: (
349
+ assertion<VitestExtras__Mock.mockFn4<'a, 'b, 'c, 'd, 'ret>>,
350
+ int,
351
+ 'a,
352
+ 'b,
353
+ 'c,
354
+ 'd,
355
+ ) => unit = "nthCalledWith"
356
+
357
+ @send
358
+ external nthCalledWith5: (
359
+ assertion<VitestExtras__Mock.mockFn5<'a, 'b, 'c, 'd, 'e, 'ret>>,
360
+ int,
361
+ 'a,
362
+ 'b,
363
+ 'c,
364
+ 'd,
365
+ 'e,
366
+ ) => unit = "nthCalledWith"
367
+
368
+ // =============================================================================
369
+ // Return Value Matchers
370
+ // =============================================================================
371
+
372
+ /** Asserts the mock returned successfully at least once (didn't throw) */
373
+ @send external toHaveReturned: assertion<'mock> => unit = "toHaveReturned"
374
+
375
+ /** Alias for toHaveReturned */
376
+ @send external toReturn: assertion<'mock> => unit = "toReturn"
377
+
378
+ /** Asserts the mock returned successfully exactly n times */
379
+ @send external toHaveReturnedTimes: (assertion<'mock>, int) => unit = "toHaveReturnedTimes"
380
+
381
+ /** Alias for toHaveReturnedTimes */
382
+ @send external toReturnTimes: (assertion<'mock>, int) => unit = "toReturnTimes"
383
+
384
+ /** Asserts the mock returned a specific value */
385
+ @send external toHaveReturnedWith: (assertion<'mock>, 'ret) => unit = "toHaveReturnedWith"
386
+
387
+ /** Alias for toHaveReturnedWith */
388
+ @send external toReturnWith: (assertion<'mock>, 'ret) => unit = "toReturnWith"
389
+
390
+ /** Asserts the mock's last return value */
391
+ @send external toHaveLastReturnedWith: (assertion<'mock>, 'ret) => unit = "toHaveLastReturnedWith"
392
+
393
+ /** Alias for toHaveLastReturnedWith */
394
+ @send external lastReturnedWith: (assertion<'mock>, 'ret) => unit = "lastReturnedWith"
395
+
396
+ /** Asserts the nth call returned a specific value */
397
+ @send
398
+ external toHaveNthReturnedWith: (assertion<'mock>, int, 'ret) => unit = "toHaveNthReturnedWith"
399
+
400
+ /** Alias for toHaveNthReturnedWith */
401
+ @send external nthReturnedWith: (assertion<'mock>, int, 'ret) => unit = "nthReturnedWith"
402
+
403
+ // =============================================================================
404
+ // Call Order Matchers
405
+ // =============================================================================
406
+
407
+ /** Type for any MockInstance (used in call order matchers) */
408
+ type anyMockInstance
409
+
410
+ /** Convert any mock function to anyMockInstance for call order comparison */
411
+ external toAnyMockInstance: 'mock => anyMockInstance = "%identity"
412
+
413
+ /** Asserts this mock was called before another mock */
414
+ @send
415
+ external toHaveBeenCalledBefore: (
416
+ assertion<'mock>,
417
+ anyMockInstance,
418
+ ~failIfNoFirstInvocation: bool=?,
419
+ ) => unit = "toHaveBeenCalledBefore"
420
+
421
+ /** Asserts this mock was called after another mock */
422
+ @send
423
+ external toHaveBeenCalledAfter: (
424
+ assertion<'mock>,
425
+ anyMockInstance,
426
+ ~failIfNoFirstInvocation: bool=?,
427
+ ) => unit = "toHaveBeenCalledAfter"
428
+
429
+ // =============================================================================
430
+ // Negation Support
431
+ // =============================================================================
432
+
433
+ /** Get the negated assertion for mock matchers */
434
+ @get external not: assertion<'mock> => assertion<'mock> = "not"
435
+
436
+ // =============================================================================
437
+ // Promise/Async Resolution Matchers
438
+ // =============================================================================
439
+
440
+ /** Asserts an async mock resolved at least once */
441
+ @send external toHaveResolved: assertion<'mock> => unit = "toHaveResolved"
442
+
443
+ /** Asserts an async mock resolved with a specific value */
444
+ @send external toHaveResolvedWith: (assertion<'mock>, 'ret) => unit = "toHaveResolvedWith"
445
+
446
+ /** Asserts an async mock resolved exactly n times */
447
+ @send external toHaveResolvedTimes: (assertion<'mock>, int) => unit = "toHaveResolvedTimes"
448
+
449
+ /** Asserts the last resolved value of an async mock */
450
+ @send
451
+ external toHaveLastResolvedWith: (assertion<'mock>, 'ret) => unit = "toHaveLastResolvedWith"
452
+
453
+ /** Asserts the nth resolved value of an async mock */
454
+ @send
455
+ external toHaveNthResolvedWith: (assertion<'mock>, int, 'ret) => unit = "toHaveNthResolvedWith"