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.
- package/.yarnrc.yml +1 -0
- package/CHANGELOG.md +16 -0
- package/README.md +187 -0
- package/package.json +47 -0
- package/rescript.json +34 -0
- package/src/VitestExtras.res +8 -0
- package/src/VitestExtras__Assert.res +627 -0
- package/src/VitestExtras__Assert.resi +302 -0
- package/src/VitestExtras__BrowserExpect.res +159 -0
- package/src/VitestExtras__BrowserExpect.resi +159 -0
- package/src/VitestExtras__BrowserLocator.res +190 -0
- package/src/VitestExtras__BrowserLocator.resi +190 -0
- package/src/VitestExtras__BrowserPage.res +119 -0
- package/src/VitestExtras__BrowserPage.resi +62 -0
- package/src/VitestExtras__BrowserReact.res +201 -0
- package/src/VitestExtras__BrowserReact.resi +201 -0
- package/src/VitestExtras__BrowserUserEvent.res +200 -0
- package/src/VitestExtras__BrowserUserEvent.resi +109 -0
- package/src/VitestExtras__Mock.res +639 -0
- package/src/VitestExtras__Mock.resi +432 -0
- package/src/VitestExtras__MockExpect.res +455 -0
|
@@ -0,0 +1,639 @@
|
|
|
1
|
+
// VitestMock.res - Strongly-typed bindings for Vitest's mocking API
|
|
2
|
+
//
|
|
3
|
+
// Design notes:
|
|
4
|
+
// - Separate types per arity (mockFn0, mockFn1, etc.) for type safety
|
|
5
|
+
// - Mock functions are callable via external bindings
|
|
6
|
+
// - Uses @unboxed variants for mock result types (zero-cost)
|
|
7
|
+
|
|
8
|
+
// =============================================================================
|
|
9
|
+
// Mock Result Types
|
|
10
|
+
// =============================================================================
|
|
11
|
+
|
|
12
|
+
/** Type of a mock result - discriminator field */
|
|
13
|
+
type mockResultType = [#return | #incomplete | #throw]
|
|
14
|
+
|
|
15
|
+
/** Result of a single mock function invocation.
|
|
16
|
+
Use `type_` to discriminate:
|
|
17
|
+
- #return: successful return, `value` contains the return value
|
|
18
|
+
- #incomplete: function hasn't returned yet
|
|
19
|
+
- #throw: function threw an error, `value` contains the error */
|
|
20
|
+
type mockResult<'ret> = {
|
|
21
|
+
@as("type") type_: mockResultType,
|
|
22
|
+
value: 'ret,
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Type of a settled result - discriminator field */
|
|
26
|
+
type mockSettledResultType = [#fulfilled | #rejected]
|
|
27
|
+
|
|
28
|
+
/** Settled result for async mock functions.
|
|
29
|
+
Use `type_` to discriminate:
|
|
30
|
+
- #fulfilled: promise resolved, `value` contains the resolved value
|
|
31
|
+
- #rejected: promise rejected, `value` contains the rejection reason */
|
|
32
|
+
type mockSettledResult<'ret> = {
|
|
33
|
+
@as("type") type_: mockSettledResultType,
|
|
34
|
+
value: 'ret,
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// =============================================================================
|
|
38
|
+
// Mock Context Types (per arity)
|
|
39
|
+
// =============================================================================
|
|
40
|
+
|
|
41
|
+
/** Context for 0-arity mock functions */
|
|
42
|
+
type mockContext0<'ret> = {
|
|
43
|
+
calls: array<unit>,
|
|
44
|
+
instances: array<'ret>,
|
|
45
|
+
contexts: array<unknown>,
|
|
46
|
+
invocationCallOrder: array<int>,
|
|
47
|
+
results: array<mockResult<'ret>>,
|
|
48
|
+
settledResults: array<mockSettledResult<'ret>>,
|
|
49
|
+
lastCall: option<unit>,
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Context for 1-arity mock functions.
|
|
53
|
+
Note: calls and lastCall use array<'a> because Vitest stores
|
|
54
|
+
single-argument calls as [arg] arrays */
|
|
55
|
+
type mockContext1<'a, 'ret> = {
|
|
56
|
+
calls: array<array<'a>>,
|
|
57
|
+
instances: array<'ret>,
|
|
58
|
+
contexts: array<unknown>,
|
|
59
|
+
invocationCallOrder: array<int>,
|
|
60
|
+
results: array<mockResult<'ret>>,
|
|
61
|
+
settledResults: array<mockSettledResult<'ret>>,
|
|
62
|
+
lastCall: option<array<'a>>,
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Context for 2-arity mock functions */
|
|
66
|
+
type mockContext2<'a, 'b, 'ret> = {
|
|
67
|
+
calls: array<('a, 'b)>,
|
|
68
|
+
instances: array<'ret>,
|
|
69
|
+
contexts: array<unknown>,
|
|
70
|
+
invocationCallOrder: array<int>,
|
|
71
|
+
results: array<mockResult<'ret>>,
|
|
72
|
+
settledResults: array<mockSettledResult<'ret>>,
|
|
73
|
+
lastCall: option<('a, 'b)>,
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Context for 3-arity mock functions */
|
|
77
|
+
type mockContext3<'a, 'b, 'c, 'ret> = {
|
|
78
|
+
calls: array<('a, 'b, 'c)>,
|
|
79
|
+
instances: array<'ret>,
|
|
80
|
+
contexts: array<unknown>,
|
|
81
|
+
invocationCallOrder: array<int>,
|
|
82
|
+
results: array<mockResult<'ret>>,
|
|
83
|
+
settledResults: array<mockSettledResult<'ret>>,
|
|
84
|
+
lastCall: option<('a, 'b, 'c)>,
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Context for 4-arity mock functions */
|
|
88
|
+
type mockContext4<'a, 'b, 'c, 'd, 'ret> = {
|
|
89
|
+
calls: array<('a, 'b, 'c, 'd)>,
|
|
90
|
+
instances: array<'ret>,
|
|
91
|
+
contexts: array<unknown>,
|
|
92
|
+
invocationCallOrder: array<int>,
|
|
93
|
+
results: array<mockResult<'ret>>,
|
|
94
|
+
settledResults: array<mockSettledResult<'ret>>,
|
|
95
|
+
lastCall: option<('a, 'b, 'c, 'd)>,
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Context for 5-arity mock functions */
|
|
99
|
+
type mockContext5<'a, 'b, 'c, 'd, 'e, 'ret> = {
|
|
100
|
+
calls: array<('a, 'b, 'c, 'd, 'e)>,
|
|
101
|
+
instances: array<'ret>,
|
|
102
|
+
contexts: array<unknown>,
|
|
103
|
+
invocationCallOrder: array<int>,
|
|
104
|
+
results: array<mockResult<'ret>>,
|
|
105
|
+
settledResults: array<mockSettledResult<'ret>>,
|
|
106
|
+
lastCall: option<('a, 'b, 'c, 'd, 'e)>,
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// =============================================================================
|
|
110
|
+
// Mock Function Types (per arity)
|
|
111
|
+
// =============================================================================
|
|
112
|
+
|
|
113
|
+
/** Mock function with 0 arguments: () => 'ret */
|
|
114
|
+
type mockFn0<'ret>
|
|
115
|
+
|
|
116
|
+
/** Mock function with 1 argument: 'a => 'ret */
|
|
117
|
+
type mockFn1<'a, 'ret>
|
|
118
|
+
|
|
119
|
+
/** Mock function with 2 arguments: ('a, 'b) => 'ret */
|
|
120
|
+
type mockFn2<'a, 'b, 'ret>
|
|
121
|
+
|
|
122
|
+
/** Mock function with 3 arguments: ('a, 'b, 'c) => 'ret */
|
|
123
|
+
type mockFn3<'a, 'b, 'c, 'ret>
|
|
124
|
+
|
|
125
|
+
/** Mock function with 4 arguments: ('a, 'b, 'c, 'd) => 'ret */
|
|
126
|
+
type mockFn4<'a, 'b, 'c, 'd, 'ret>
|
|
127
|
+
|
|
128
|
+
/** Mock function with 5 arguments: ('a, 'b, 'c, 'd, 'e) => 'ret */
|
|
129
|
+
type mockFn5<'a, 'b, 'c, 'd, 'e, 'ret>
|
|
130
|
+
|
|
131
|
+
// =============================================================================
|
|
132
|
+
// vi.fn() - Create Mock Functions
|
|
133
|
+
// =============================================================================
|
|
134
|
+
|
|
135
|
+
@module("vitest") @val external vi: Vitest.Vi.t = "vi"
|
|
136
|
+
|
|
137
|
+
/** Create a mock function with 0 arguments.
|
|
138
|
+
Note: When called without implementation, will return undefined at runtime.
|
|
139
|
+
For type safety, either:
|
|
140
|
+
- Annotate the type: `let mock: mockFn0<int> = fn0()`
|
|
141
|
+
- Use fnWithImpl0: `let mock = fnWithImpl0(() => 42)` */
|
|
142
|
+
@send external fn0: Vitest.Vi.t => mockFn0<'ret> = "fn"
|
|
143
|
+
|
|
144
|
+
/** Create a mock function with an implementation: () => 'ret */
|
|
145
|
+
@send
|
|
146
|
+
external fnWithImpl0: (Vitest.Vi.t, unit => 'ret) => mockFn0<'ret> = "fn"
|
|
147
|
+
|
|
148
|
+
/** Create a mock function with 1 argument.
|
|
149
|
+
Note: When called without implementation, will return undefined at runtime. */
|
|
150
|
+
@send external fn1: Vitest.Vi.t => mockFn1<'a, 'ret> = "fn"
|
|
151
|
+
|
|
152
|
+
/** Create a mock function with an implementation: 'a => 'ret */
|
|
153
|
+
@send
|
|
154
|
+
external fnWithImpl1: (Vitest.Vi.t, 'a => 'ret) => mockFn1<'a, 'ret> = "fn"
|
|
155
|
+
|
|
156
|
+
/** Create a mock function with 2 arguments.
|
|
157
|
+
Note: When called without implementation, will return undefined at runtime. */
|
|
158
|
+
@send external fn2: Vitest.Vi.t => mockFn2<'a, 'b, 'ret> = "fn"
|
|
159
|
+
|
|
160
|
+
/** Create a mock function with an implementation: ('a, 'b) => 'ret */
|
|
161
|
+
@send
|
|
162
|
+
external fnWithImpl2: (Vitest.Vi.t, ('a, 'b) => 'ret) => mockFn2<'a, 'b, 'ret> = "fn"
|
|
163
|
+
|
|
164
|
+
/** Create a mock function with 3 arguments.
|
|
165
|
+
Note: When called without implementation, will return undefined at runtime. */
|
|
166
|
+
@send external fn3: Vitest.Vi.t => mockFn3<'a, 'b, 'c, 'ret> = "fn"
|
|
167
|
+
|
|
168
|
+
/** Create a mock function with an implementation: ('a, 'b, 'c) => 'ret */
|
|
169
|
+
@send
|
|
170
|
+
external fnWithImpl3: (Vitest.Vi.t, ('a, 'b, 'c) => 'ret) => mockFn3<'a, 'b, 'c, 'ret> = "fn"
|
|
171
|
+
|
|
172
|
+
/** Create a mock function with 4 arguments.
|
|
173
|
+
Note: When called without implementation, will return undefined at runtime. */
|
|
174
|
+
@send external fn4: Vitest.Vi.t => mockFn4<'a, 'b, 'c, 'd, 'ret> = "fn"
|
|
175
|
+
|
|
176
|
+
/** Create a mock function with an implementation: ('a, 'b, 'c, 'd) => 'ret */
|
|
177
|
+
@send
|
|
178
|
+
external fnWithImpl4: (Vitest.Vi.t, ('a, 'b, 'c, 'd) => 'ret) => mockFn4<'a, 'b, 'c, 'd, 'ret> =
|
|
179
|
+
"fn"
|
|
180
|
+
|
|
181
|
+
/** Create a mock function with 5 arguments.
|
|
182
|
+
Note: When called without implementation, will return undefined at runtime. */
|
|
183
|
+
@send external fn5: Vitest.Vi.t => mockFn5<'a, 'b, 'c, 'd, 'e, 'ret> = "fn"
|
|
184
|
+
|
|
185
|
+
/** Create a mock function with an implementation: ('a, 'b, 'c, 'd, 'e) => 'ret */
|
|
186
|
+
@send
|
|
187
|
+
external fnWithImpl5: (
|
|
188
|
+
Vitest.Vi.t,
|
|
189
|
+
('a, 'b, 'c, 'd, 'e) => 'ret,
|
|
190
|
+
) => mockFn5<'a, 'b, 'c, 'd, 'e, 'ret> = "fn"
|
|
191
|
+
|
|
192
|
+
// Convenience functions that don't require passing vi
|
|
193
|
+
let fn0 = () => vi->fn0
|
|
194
|
+
let fnWithImpl0 = impl => vi->fnWithImpl0(impl)
|
|
195
|
+
let fn1 = () => vi->fn1
|
|
196
|
+
let fnWithImpl1 = impl => vi->fnWithImpl1(impl)
|
|
197
|
+
let fn2 = () => vi->fn2
|
|
198
|
+
let fnWithImpl2 = impl => vi->fnWithImpl2(impl)
|
|
199
|
+
let fn3 = () => vi->fn3
|
|
200
|
+
let fnWithImpl3 = impl => vi->fnWithImpl3(impl)
|
|
201
|
+
let fn4 = () => vi->fn4
|
|
202
|
+
let fnWithImpl4 = impl => vi->fnWithImpl4(impl)
|
|
203
|
+
let fn5 = () => vi->fn5
|
|
204
|
+
let fnWithImpl5 = impl => vi->fnWithImpl5(impl)
|
|
205
|
+
|
|
206
|
+
// =============================================================================
|
|
207
|
+
// Mock Instance Methods - mockFn0
|
|
208
|
+
// =============================================================================
|
|
209
|
+
|
|
210
|
+
module MockFn0 = {
|
|
211
|
+
/** Get the mock context containing calls, results, etc. */
|
|
212
|
+
@get external mock: mockFn0<'ret> => mockContext0<'ret> = "mock"
|
|
213
|
+
|
|
214
|
+
/** Get the mock function name */
|
|
215
|
+
@send external getMockName: mockFn0<'ret> => string = "getMockName"
|
|
216
|
+
|
|
217
|
+
/** Set the mock function name */
|
|
218
|
+
@send external mockName: (mockFn0<'ret>, string) => mockFn0<'ret> = "mockName"
|
|
219
|
+
|
|
220
|
+
/** Clear all information about every call */
|
|
221
|
+
@send external mockClear: mockFn0<'ret> => mockFn0<'ret> = "mockClear"
|
|
222
|
+
|
|
223
|
+
/** Clear and reset to original implementation */
|
|
224
|
+
@send external mockReset: mockFn0<'ret> => mockFn0<'ret> = "mockReset"
|
|
225
|
+
|
|
226
|
+
/** Restore original implementation (for spies) */
|
|
227
|
+
@send external mockRestore: mockFn0<'ret> => unit = "mockRestore"
|
|
228
|
+
|
|
229
|
+
/** Get current mock implementation */
|
|
230
|
+
@send @return(nullable)
|
|
231
|
+
external getMockImplementation: mockFn0<'ret> => option<unit => 'ret> = "getMockImplementation"
|
|
232
|
+
|
|
233
|
+
/** Set mock implementation */
|
|
234
|
+
@send
|
|
235
|
+
external mockImplementation: (mockFn0<'ret>, unit => 'ret) => mockFn0<'ret> = "mockImplementation"
|
|
236
|
+
|
|
237
|
+
/** Set mock implementation for next call only */
|
|
238
|
+
@send
|
|
239
|
+
external mockImplementationOnce: (mockFn0<'ret>, unit => 'ret) => mockFn0<'ret> =
|
|
240
|
+
"mockImplementationOnce"
|
|
241
|
+
|
|
242
|
+
/** Return `this` when called */
|
|
243
|
+
@send external mockReturnThis: mockFn0<'ret> => mockFn0<'ret> = "mockReturnThis"
|
|
244
|
+
|
|
245
|
+
/** Set return value for all calls */
|
|
246
|
+
@send
|
|
247
|
+
external mockReturnValue: (mockFn0<'ret>, 'ret) => mockFn0<'ret> = "mockReturnValue"
|
|
248
|
+
|
|
249
|
+
/** Set return value for next call only */
|
|
250
|
+
@send
|
|
251
|
+
external mockReturnValueOnce: (mockFn0<'ret>, 'ret) => mockFn0<'ret> = "mockReturnValueOnce"
|
|
252
|
+
|
|
253
|
+
/** Set resolved value for async mock */
|
|
254
|
+
@send
|
|
255
|
+
external mockResolvedValue: (mockFn0<promise<'ret>>, 'ret) => mockFn0<promise<'ret>> =
|
|
256
|
+
"mockResolvedValue"
|
|
257
|
+
|
|
258
|
+
/** Set resolved value for next async call only */
|
|
259
|
+
@send
|
|
260
|
+
external mockResolvedValueOnce: (mockFn0<promise<'ret>>, 'ret) => mockFn0<promise<'ret>> =
|
|
261
|
+
"mockResolvedValueOnce"
|
|
262
|
+
|
|
263
|
+
/** Set rejected value for async mock */
|
|
264
|
+
@send
|
|
265
|
+
external mockRejectedValue: (mockFn0<promise<'ret>>, unknown) => mockFn0<promise<'ret>> =
|
|
266
|
+
"mockRejectedValue"
|
|
267
|
+
|
|
268
|
+
/** Set rejected value for next async call only */
|
|
269
|
+
@send
|
|
270
|
+
external mockRejectedValueOnce: (mockFn0<promise<'ret>>, unknown) => mockFn0<promise<'ret>> =
|
|
271
|
+
"mockRejectedValueOnce"
|
|
272
|
+
|
|
273
|
+
/** Convert to a callable function */
|
|
274
|
+
external toFunction: mockFn0<'ret> => unit => 'ret = "%identity"
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// =============================================================================
|
|
278
|
+
// Mock Instance Methods - mockFn1
|
|
279
|
+
// =============================================================================
|
|
280
|
+
|
|
281
|
+
module MockFn1 = {
|
|
282
|
+
@get external mock: mockFn1<'a, 'ret> => mockContext1<'a, 'ret> = "mock"
|
|
283
|
+
@send external getMockName: mockFn1<'a, 'ret> => string = "getMockName"
|
|
284
|
+
@send external mockName: (mockFn1<'a, 'ret>, string) => mockFn1<'a, 'ret> = "mockName"
|
|
285
|
+
@send external mockClear: mockFn1<'a, 'ret> => mockFn1<'a, 'ret> = "mockClear"
|
|
286
|
+
@send external mockReset: mockFn1<'a, 'ret> => mockFn1<'a, 'ret> = "mockReset"
|
|
287
|
+
@send external mockRestore: mockFn1<'a, 'ret> => unit = "mockRestore"
|
|
288
|
+
|
|
289
|
+
@send @return(nullable)
|
|
290
|
+
external getMockImplementation: mockFn1<'a, 'ret> => option<'a => 'ret> = "getMockImplementation"
|
|
291
|
+
|
|
292
|
+
@send
|
|
293
|
+
external mockImplementation: (mockFn1<'a, 'ret>, 'a => 'ret) => mockFn1<'a, 'ret> =
|
|
294
|
+
"mockImplementation"
|
|
295
|
+
|
|
296
|
+
@send
|
|
297
|
+
external mockImplementationOnce: (mockFn1<'a, 'ret>, 'a => 'ret) => mockFn1<'a, 'ret> =
|
|
298
|
+
"mockImplementationOnce"
|
|
299
|
+
|
|
300
|
+
@send external mockReturnThis: mockFn1<'a, 'ret> => mockFn1<'a, 'ret> = "mockReturnThis"
|
|
301
|
+
|
|
302
|
+
@send
|
|
303
|
+
external mockReturnValue: (mockFn1<'a, 'ret>, 'ret) => mockFn1<'a, 'ret> = "mockReturnValue"
|
|
304
|
+
|
|
305
|
+
@send
|
|
306
|
+
external mockReturnValueOnce: (mockFn1<'a, 'ret>, 'ret) => mockFn1<'a, 'ret> =
|
|
307
|
+
"mockReturnValueOnce"
|
|
308
|
+
|
|
309
|
+
@send
|
|
310
|
+
external mockResolvedValue: (mockFn1<'a, promise<'ret>>, 'ret) => mockFn1<'a, promise<'ret>> =
|
|
311
|
+
"mockResolvedValue"
|
|
312
|
+
|
|
313
|
+
@send
|
|
314
|
+
external mockResolvedValueOnce: (mockFn1<'a, promise<'ret>>, 'ret) => mockFn1<'a, promise<'ret>> =
|
|
315
|
+
"mockResolvedValueOnce"
|
|
316
|
+
|
|
317
|
+
@send
|
|
318
|
+
external mockRejectedValue: (mockFn1<'a, promise<'ret>>, unknown) => mockFn1<'a, promise<'ret>> =
|
|
319
|
+
"mockRejectedValue"
|
|
320
|
+
|
|
321
|
+
@send
|
|
322
|
+
external mockRejectedValueOnce: (
|
|
323
|
+
mockFn1<'a, promise<'ret>>,
|
|
324
|
+
unknown,
|
|
325
|
+
) => mockFn1<'a, promise<'ret>> = "mockRejectedValueOnce"
|
|
326
|
+
|
|
327
|
+
external toFunction: mockFn1<'a, 'ret> => 'a => 'ret = "%identity"
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// =============================================================================
|
|
331
|
+
// Mock Instance Methods - mockFn2
|
|
332
|
+
// =============================================================================
|
|
333
|
+
|
|
334
|
+
module MockFn2 = {
|
|
335
|
+
@get external mock: mockFn2<'a, 'b, 'ret> => mockContext2<'a, 'b, 'ret> = "mock"
|
|
336
|
+
@send external getMockName: mockFn2<'a, 'b, 'ret> => string = "getMockName"
|
|
337
|
+
@send
|
|
338
|
+
external mockName: (mockFn2<'a, 'b, 'ret>, string) => mockFn2<'a, 'b, 'ret> = "mockName"
|
|
339
|
+
@send external mockClear: mockFn2<'a, 'b, 'ret> => mockFn2<'a, 'b, 'ret> = "mockClear"
|
|
340
|
+
@send external mockReset: mockFn2<'a, 'b, 'ret> => mockFn2<'a, 'b, 'ret> = "mockReset"
|
|
341
|
+
@send external mockRestore: mockFn2<'a, 'b, 'ret> => unit = "mockRestore"
|
|
342
|
+
|
|
343
|
+
@send @return(nullable)
|
|
344
|
+
external getMockImplementation: mockFn2<'a, 'b, 'ret> => option<('a, 'b) => 'ret> =
|
|
345
|
+
"getMockImplementation"
|
|
346
|
+
|
|
347
|
+
@send
|
|
348
|
+
external mockImplementation: (mockFn2<'a, 'b, 'ret>, ('a, 'b) => 'ret) => mockFn2<'a, 'b, 'ret> =
|
|
349
|
+
"mockImplementation"
|
|
350
|
+
|
|
351
|
+
@send
|
|
352
|
+
external mockImplementationOnce: (
|
|
353
|
+
mockFn2<'a, 'b, 'ret>,
|
|
354
|
+
('a, 'b) => 'ret,
|
|
355
|
+
) => mockFn2<'a, 'b, 'ret> = "mockImplementationOnce"
|
|
356
|
+
|
|
357
|
+
@send
|
|
358
|
+
external mockReturnThis: mockFn2<'a, 'b, 'ret> => mockFn2<'a, 'b, 'ret> = "mockReturnThis"
|
|
359
|
+
|
|
360
|
+
@send
|
|
361
|
+
external mockReturnValue: (mockFn2<'a, 'b, 'ret>, 'ret) => mockFn2<'a, 'b, 'ret> =
|
|
362
|
+
"mockReturnValue"
|
|
363
|
+
|
|
364
|
+
@send
|
|
365
|
+
external mockReturnValueOnce: (mockFn2<'a, 'b, 'ret>, 'ret) => mockFn2<'a, 'b, 'ret> =
|
|
366
|
+
"mockReturnValueOnce"
|
|
367
|
+
|
|
368
|
+
@send
|
|
369
|
+
external mockResolvedValue: (
|
|
370
|
+
mockFn2<'a, 'b, promise<'ret>>,
|
|
371
|
+
'ret,
|
|
372
|
+
) => mockFn2<'a, 'b, promise<'ret>> = "mockResolvedValue"
|
|
373
|
+
|
|
374
|
+
@send
|
|
375
|
+
external mockResolvedValueOnce: (
|
|
376
|
+
mockFn2<'a, 'b, promise<'ret>>,
|
|
377
|
+
'ret,
|
|
378
|
+
) => mockFn2<'a, 'b, promise<'ret>> = "mockResolvedValueOnce"
|
|
379
|
+
|
|
380
|
+
@send
|
|
381
|
+
external mockRejectedValue: (
|
|
382
|
+
mockFn2<'a, 'b, promise<'ret>>,
|
|
383
|
+
unknown,
|
|
384
|
+
) => mockFn2<'a, 'b, promise<'ret>> = "mockRejectedValue"
|
|
385
|
+
|
|
386
|
+
@send
|
|
387
|
+
external mockRejectedValueOnce: (
|
|
388
|
+
mockFn2<'a, 'b, promise<'ret>>,
|
|
389
|
+
unknown,
|
|
390
|
+
) => mockFn2<'a, 'b, promise<'ret>> = "mockRejectedValueOnce"
|
|
391
|
+
|
|
392
|
+
external toFunction: mockFn2<'a, 'b, 'ret> => ('a, 'b) => 'ret = "%identity"
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// =============================================================================
|
|
396
|
+
// Mock Instance Methods - mockFn3
|
|
397
|
+
// =============================================================================
|
|
398
|
+
|
|
399
|
+
module MockFn3 = {
|
|
400
|
+
@get external mock: mockFn3<'a, 'b, 'c, 'ret> => mockContext3<'a, 'b, 'c, 'ret> = "mock"
|
|
401
|
+
@send external getMockName: mockFn3<'a, 'b, 'c, 'ret> => string = "getMockName"
|
|
402
|
+
@send
|
|
403
|
+
external mockName: (mockFn3<'a, 'b, 'c, 'ret>, string) => mockFn3<'a, 'b, 'c, 'ret> = "mockName"
|
|
404
|
+
@send
|
|
405
|
+
external mockClear: mockFn3<'a, 'b, 'c, 'ret> => mockFn3<'a, 'b, 'c, 'ret> = "mockClear"
|
|
406
|
+
@send
|
|
407
|
+
external mockReset: mockFn3<'a, 'b, 'c, 'ret> => mockFn3<'a, 'b, 'c, 'ret> = "mockReset"
|
|
408
|
+
@send external mockRestore: mockFn3<'a, 'b, 'c, 'ret> => unit = "mockRestore"
|
|
409
|
+
|
|
410
|
+
@send @return(nullable)
|
|
411
|
+
external getMockImplementation: mockFn3<'a, 'b, 'c, 'ret> => option<('a, 'b, 'c) => 'ret> =
|
|
412
|
+
"getMockImplementation"
|
|
413
|
+
|
|
414
|
+
@send
|
|
415
|
+
external mockImplementation: (
|
|
416
|
+
mockFn3<'a, 'b, 'c, 'ret>,
|
|
417
|
+
('a, 'b, 'c) => 'ret,
|
|
418
|
+
) => mockFn3<'a, 'b, 'c, 'ret> = "mockImplementation"
|
|
419
|
+
|
|
420
|
+
@send
|
|
421
|
+
external mockImplementationOnce: (
|
|
422
|
+
mockFn3<'a, 'b, 'c, 'ret>,
|
|
423
|
+
('a, 'b, 'c) => 'ret,
|
|
424
|
+
) => mockFn3<'a, 'b, 'c, 'ret> = "mockImplementationOnce"
|
|
425
|
+
|
|
426
|
+
@send
|
|
427
|
+
external mockReturnThis: mockFn3<'a, 'b, 'c, 'ret> => mockFn3<'a, 'b, 'c, 'ret> = "mockReturnThis"
|
|
428
|
+
|
|
429
|
+
@send
|
|
430
|
+
external mockReturnValue: (mockFn3<'a, 'b, 'c, 'ret>, 'ret) => mockFn3<'a, 'b, 'c, 'ret> =
|
|
431
|
+
"mockReturnValue"
|
|
432
|
+
|
|
433
|
+
@send
|
|
434
|
+
external mockReturnValueOnce: (mockFn3<'a, 'b, 'c, 'ret>, 'ret) => mockFn3<'a, 'b, 'c, 'ret> =
|
|
435
|
+
"mockReturnValueOnce"
|
|
436
|
+
|
|
437
|
+
@send
|
|
438
|
+
external mockResolvedValue: (
|
|
439
|
+
mockFn3<'a, 'b, 'c, promise<'ret>>,
|
|
440
|
+
'ret,
|
|
441
|
+
) => mockFn3<'a, 'b, 'c, promise<'ret>> = "mockResolvedValue"
|
|
442
|
+
|
|
443
|
+
@send
|
|
444
|
+
external mockResolvedValueOnce: (
|
|
445
|
+
mockFn3<'a, 'b, 'c, promise<'ret>>,
|
|
446
|
+
'ret,
|
|
447
|
+
) => mockFn3<'a, 'b, 'c, promise<'ret>> = "mockResolvedValueOnce"
|
|
448
|
+
|
|
449
|
+
@send
|
|
450
|
+
external mockRejectedValue: (
|
|
451
|
+
mockFn3<'a, 'b, 'c, promise<'ret>>,
|
|
452
|
+
unknown,
|
|
453
|
+
) => mockFn3<'a, 'b, 'c, promise<'ret>> = "mockRejectedValue"
|
|
454
|
+
|
|
455
|
+
@send
|
|
456
|
+
external mockRejectedValueOnce: (
|
|
457
|
+
mockFn3<'a, 'b, 'c, promise<'ret>>,
|
|
458
|
+
unknown,
|
|
459
|
+
) => mockFn3<'a, 'b, 'c, promise<'ret>> = "mockRejectedValueOnce"
|
|
460
|
+
|
|
461
|
+
external toFunction: mockFn3<'a, 'b, 'c, 'ret> => ('a, 'b, 'c) => 'ret = "%identity"
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
// =============================================================================
|
|
465
|
+
// Mock Instance Methods - mockFn4
|
|
466
|
+
// =============================================================================
|
|
467
|
+
|
|
468
|
+
module MockFn4 = {
|
|
469
|
+
@get
|
|
470
|
+
external mock: mockFn4<'a, 'b, 'c, 'd, 'ret> => mockContext4<'a, 'b, 'c, 'd, 'ret> = "mock"
|
|
471
|
+
@send external getMockName: mockFn4<'a, 'b, 'c, 'd, 'ret> => string = "getMockName"
|
|
472
|
+
@send
|
|
473
|
+
external mockName: (mockFn4<'a, 'b, 'c, 'd, 'ret>, string) => mockFn4<'a, 'b, 'c, 'd, 'ret> =
|
|
474
|
+
"mockName"
|
|
475
|
+
@send
|
|
476
|
+
external mockClear: mockFn4<'a, 'b, 'c, 'd, 'ret> => mockFn4<'a, 'b, 'c, 'd, 'ret> = "mockClear"
|
|
477
|
+
@send
|
|
478
|
+
external mockReset: mockFn4<'a, 'b, 'c, 'd, 'ret> => mockFn4<'a, 'b, 'c, 'd, 'ret> = "mockReset"
|
|
479
|
+
@send external mockRestore: mockFn4<'a, 'b, 'c, 'd, 'ret> => unit = "mockRestore"
|
|
480
|
+
|
|
481
|
+
@send @return(nullable)
|
|
482
|
+
external getMockImplementation: mockFn4<'a, 'b, 'c, 'd, 'ret> => option<
|
|
483
|
+
('a, 'b, 'c, 'd) => 'ret,
|
|
484
|
+
> = "getMockImplementation"
|
|
485
|
+
|
|
486
|
+
@send
|
|
487
|
+
external mockImplementation: (
|
|
488
|
+
mockFn4<'a, 'b, 'c, 'd, 'ret>,
|
|
489
|
+
('a, 'b, 'c, 'd) => 'ret,
|
|
490
|
+
) => mockFn4<'a, 'b, 'c, 'd, 'ret> = "mockImplementation"
|
|
491
|
+
|
|
492
|
+
@send
|
|
493
|
+
external mockImplementationOnce: (
|
|
494
|
+
mockFn4<'a, 'b, 'c, 'd, 'ret>,
|
|
495
|
+
('a, 'b, 'c, 'd) => 'ret,
|
|
496
|
+
) => mockFn4<'a, 'b, 'c, 'd, 'ret> = "mockImplementationOnce"
|
|
497
|
+
|
|
498
|
+
@send
|
|
499
|
+
external mockReturnThis: mockFn4<'a, 'b, 'c, 'd, 'ret> => mockFn4<'a, 'b, 'c, 'd, 'ret> =
|
|
500
|
+
"mockReturnThis"
|
|
501
|
+
|
|
502
|
+
@send
|
|
503
|
+
external mockReturnValue: (mockFn4<'a, 'b, 'c, 'd, 'ret>, 'ret) => mockFn4<'a, 'b, 'c, 'd, 'ret> =
|
|
504
|
+
"mockReturnValue"
|
|
505
|
+
|
|
506
|
+
@send
|
|
507
|
+
external mockReturnValueOnce: (
|
|
508
|
+
mockFn4<'a, 'b, 'c, 'd, 'ret>,
|
|
509
|
+
'ret,
|
|
510
|
+
) => mockFn4<'a, 'b, 'c, 'd, 'ret> = "mockReturnValueOnce"
|
|
511
|
+
|
|
512
|
+
@send
|
|
513
|
+
external mockResolvedValue: (
|
|
514
|
+
mockFn4<'a, 'b, 'c, 'd, promise<'ret>>,
|
|
515
|
+
'ret,
|
|
516
|
+
) => mockFn4<'a, 'b, 'c, 'd, promise<'ret>> = "mockResolvedValue"
|
|
517
|
+
|
|
518
|
+
@send
|
|
519
|
+
external mockResolvedValueOnce: (
|
|
520
|
+
mockFn4<'a, 'b, 'c, 'd, promise<'ret>>,
|
|
521
|
+
'ret,
|
|
522
|
+
) => mockFn4<'a, 'b, 'c, 'd, promise<'ret>> = "mockResolvedValueOnce"
|
|
523
|
+
|
|
524
|
+
@send
|
|
525
|
+
external mockRejectedValue: (
|
|
526
|
+
mockFn4<'a, 'b, 'c, 'd, promise<'ret>>,
|
|
527
|
+
unknown,
|
|
528
|
+
) => mockFn4<'a, 'b, 'c, 'd, promise<'ret>> = "mockRejectedValue"
|
|
529
|
+
|
|
530
|
+
@send
|
|
531
|
+
external mockRejectedValueOnce: (
|
|
532
|
+
mockFn4<'a, 'b, 'c, 'd, promise<'ret>>,
|
|
533
|
+
unknown,
|
|
534
|
+
) => mockFn4<'a, 'b, 'c, 'd, promise<'ret>> = "mockRejectedValueOnce"
|
|
535
|
+
|
|
536
|
+
external toFunction: mockFn4<'a, 'b, 'c, 'd, 'ret> => ('a, 'b, 'c, 'd) => 'ret = "%identity"
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
// =============================================================================
|
|
540
|
+
// Mock Instance Methods - mockFn5
|
|
541
|
+
// =============================================================================
|
|
542
|
+
|
|
543
|
+
module MockFn5 = {
|
|
544
|
+
@get
|
|
545
|
+
external mock: mockFn5<'a, 'b, 'c, 'd, 'e, 'ret> => mockContext5<'a, 'b, 'c, 'd, 'e, 'ret> =
|
|
546
|
+
"mock"
|
|
547
|
+
@send external getMockName: mockFn5<'a, 'b, 'c, 'd, 'e, 'ret> => string = "getMockName"
|
|
548
|
+
@send
|
|
549
|
+
external mockName: (
|
|
550
|
+
mockFn5<'a, 'b, 'c, 'd, 'e, 'ret>,
|
|
551
|
+
string,
|
|
552
|
+
) => mockFn5<'a, 'b, 'c, 'd, 'e, 'ret> = "mockName"
|
|
553
|
+
@send
|
|
554
|
+
external mockClear: mockFn5<'a, 'b, 'c, 'd, 'e, 'ret> => mockFn5<'a, 'b, 'c, 'd, 'e, 'ret> =
|
|
555
|
+
"mockClear"
|
|
556
|
+
@send
|
|
557
|
+
external mockReset: mockFn5<'a, 'b, 'c, 'd, 'e, 'ret> => mockFn5<'a, 'b, 'c, 'd, 'e, 'ret> =
|
|
558
|
+
"mockReset"
|
|
559
|
+
@send external mockRestore: mockFn5<'a, 'b, 'c, 'd, 'e, 'ret> => unit = "mockRestore"
|
|
560
|
+
|
|
561
|
+
@send @return(nullable)
|
|
562
|
+
external getMockImplementation: mockFn5<'a, 'b, 'c, 'd, 'e, 'ret> => option<
|
|
563
|
+
('a, 'b, 'c, 'd, 'e) => 'ret,
|
|
564
|
+
> = "getMockImplementation"
|
|
565
|
+
|
|
566
|
+
@send
|
|
567
|
+
external mockImplementation: (
|
|
568
|
+
mockFn5<'a, 'b, 'c, 'd, 'e, 'ret>,
|
|
569
|
+
('a, 'b, 'c, 'd, 'e) => 'ret,
|
|
570
|
+
) => mockFn5<'a, 'b, 'c, 'd, 'e, 'ret> = "mockImplementation"
|
|
571
|
+
|
|
572
|
+
@send
|
|
573
|
+
external mockImplementationOnce: (
|
|
574
|
+
mockFn5<'a, 'b, 'c, 'd, 'e, 'ret>,
|
|
575
|
+
('a, 'b, 'c, 'd, 'e) => 'ret,
|
|
576
|
+
) => mockFn5<'a, 'b, 'c, 'd, 'e, 'ret> = "mockImplementationOnce"
|
|
577
|
+
|
|
578
|
+
@send
|
|
579
|
+
external mockReturnThis: mockFn5<'a, 'b, 'c, 'd, 'e, 'ret> => mockFn5<'a, 'b, 'c, 'd, 'e, 'ret> =
|
|
580
|
+
"mockReturnThis"
|
|
581
|
+
|
|
582
|
+
@send
|
|
583
|
+
external mockReturnValue: (
|
|
584
|
+
mockFn5<'a, 'b, 'c, 'd, 'e, 'ret>,
|
|
585
|
+
'ret,
|
|
586
|
+
) => mockFn5<'a, 'b, 'c, 'd, 'e, 'ret> = "mockReturnValue"
|
|
587
|
+
|
|
588
|
+
@send
|
|
589
|
+
external mockReturnValueOnce: (
|
|
590
|
+
mockFn5<'a, 'b, 'c, 'd, 'e, 'ret>,
|
|
591
|
+
'ret,
|
|
592
|
+
) => mockFn5<'a, 'b, 'c, 'd, 'e, 'ret> = "mockReturnValueOnce"
|
|
593
|
+
|
|
594
|
+
@send
|
|
595
|
+
external mockResolvedValue: (
|
|
596
|
+
mockFn5<'a, 'b, 'c, 'd, 'e, promise<'ret>>,
|
|
597
|
+
'ret,
|
|
598
|
+
) => mockFn5<'a, 'b, 'c, 'd, 'e, promise<'ret>> = "mockResolvedValue"
|
|
599
|
+
|
|
600
|
+
@send
|
|
601
|
+
external mockResolvedValueOnce: (
|
|
602
|
+
mockFn5<'a, 'b, 'c, 'd, 'e, promise<'ret>>,
|
|
603
|
+
'ret,
|
|
604
|
+
) => mockFn5<'a, 'b, 'c, 'd, 'e, promise<'ret>> = "mockResolvedValueOnce"
|
|
605
|
+
|
|
606
|
+
@send
|
|
607
|
+
external mockRejectedValue: (
|
|
608
|
+
mockFn5<'a, 'b, 'c, 'd, 'e, promise<'ret>>,
|
|
609
|
+
unknown,
|
|
610
|
+
) => mockFn5<'a, 'b, 'c, 'd, 'e, promise<'ret>> = "mockRejectedValue"
|
|
611
|
+
|
|
612
|
+
@send
|
|
613
|
+
external mockRejectedValueOnce: (
|
|
614
|
+
mockFn5<'a, 'b, 'c, 'd, 'e, promise<'ret>>,
|
|
615
|
+
unknown,
|
|
616
|
+
) => mockFn5<'a, 'b, 'c, 'd, 'e, promise<'ret>> = "mockRejectedValueOnce"
|
|
617
|
+
|
|
618
|
+
external toFunction: mockFn5<'a, 'b, 'c, 'd, 'e, 'ret> => ('a, 'b, 'c, 'd, 'e) => 'ret =
|
|
619
|
+
"%identity"
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
// =============================================================================
|
|
623
|
+
// vi.clearAllMocks, vi.resetAllMocks, vi.restoreAllMocks
|
|
624
|
+
// =============================================================================
|
|
625
|
+
|
|
626
|
+
@send external clearAllMocks: Vitest.Vi.t => Vitest.Vi.t = "clearAllMocks"
|
|
627
|
+
@send external resetAllMocks: Vitest.Vi.t => Vitest.Vi.t = "resetAllMocks"
|
|
628
|
+
@send external restoreAllMocks: Vitest.Vi.t => Vitest.Vi.t = "restoreAllMocks"
|
|
629
|
+
|
|
630
|
+
@inline let clearAllMocks = () => vi->clearAllMocks
|
|
631
|
+
@inline let resetAllMocks = () => vi->resetAllMocks
|
|
632
|
+
@inline let restoreAllMocks = () => vi->restoreAllMocks
|
|
633
|
+
|
|
634
|
+
// =============================================================================
|
|
635
|
+
// vi.isMockFunction
|
|
636
|
+
// =============================================================================
|
|
637
|
+
|
|
638
|
+
@send external isMockFunction: (Vitest.Vi.t, 'a) => bool = "isMockFunction"
|
|
639
|
+
@inline let isMockFunction = fn => vi->isMockFunction(fn)
|