@alanszp/integrations-common 10.0.0 → 11.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.
Files changed (121) hide show
  1. package/node_modules/@jest/schemas/LICENSE +21 -0
  2. package/node_modules/@jest/schemas/README.md +3 -0
  3. package/node_modules/@jest/schemas/build/index.d.ts +72 -0
  4. package/node_modules/@jest/schemas/build/index.js +65 -0
  5. package/node_modules/@jest/schemas/package.json +29 -0
  6. package/node_modules/@types/jest/LICENSE +21 -0
  7. package/node_modules/@types/jest/README.md +17 -0
  8. package/node_modules/@types/jest/index.d.ts +1684 -0
  9. package/node_modules/@types/jest/package.json +159 -0
  10. package/node_modules/@types/node/LICENSE +21 -0
  11. package/node_modules/@types/node/README.md +15 -0
  12. package/node_modules/@types/node/assert/strict.d.ts +8 -0
  13. package/node_modules/@types/node/assert.d.ts +996 -0
  14. package/node_modules/@types/node/async_hooks.d.ts +539 -0
  15. package/node_modules/@types/node/buffer.d.ts +2362 -0
  16. package/node_modules/@types/node/child_process.d.ts +1540 -0
  17. package/node_modules/@types/node/cluster.d.ts +432 -0
  18. package/node_modules/@types/node/console.d.ts +415 -0
  19. package/node_modules/@types/node/constants.d.ts +19 -0
  20. package/node_modules/@types/node/crypto.d.ts +4487 -0
  21. package/node_modules/@types/node/dgram.d.ts +596 -0
  22. package/node_modules/@types/node/diagnostics_channel.d.ts +545 -0
  23. package/node_modules/@types/node/dns/promises.d.ts +425 -0
  24. package/node_modules/@types/node/dns.d.ts +809 -0
  25. package/node_modules/@types/node/dom-events.d.ts +122 -0
  26. package/node_modules/@types/node/domain.d.ts +170 -0
  27. package/node_modules/@types/node/events.d.ts +879 -0
  28. package/node_modules/@types/node/fs/promises.d.ts +1239 -0
  29. package/node_modules/@types/node/fs.d.ts +4311 -0
  30. package/node_modules/@types/node/globals.d.ts +411 -0
  31. package/node_modules/@types/node/globals.global.d.ts +1 -0
  32. package/node_modules/@types/node/http.d.ts +1887 -0
  33. package/node_modules/@types/node/http2.d.ts +2382 -0
  34. package/node_modules/@types/node/https.d.ts +550 -0
  35. package/node_modules/@types/node/index.d.ts +88 -0
  36. package/node_modules/@types/node/inspector.d.ts +2747 -0
  37. package/node_modules/@types/node/module.d.ts +315 -0
  38. package/node_modules/@types/node/net.d.ts +949 -0
  39. package/node_modules/@types/node/os.d.ts +478 -0
  40. package/node_modules/@types/node/package.json +229 -0
  41. package/node_modules/@types/node/path.d.ts +191 -0
  42. package/node_modules/@types/node/perf_hooks.d.ts +645 -0
  43. package/node_modules/@types/node/process.d.ts +1561 -0
  44. package/node_modules/@types/node/punycode.d.ts +117 -0
  45. package/node_modules/@types/node/querystring.d.ts +141 -0
  46. package/node_modules/@types/node/readline/promises.d.ts +150 -0
  47. package/node_modules/@types/node/readline.d.ts +539 -0
  48. package/node_modules/@types/node/repl.d.ts +430 -0
  49. package/node_modules/@types/node/stream/consumers.d.ts +12 -0
  50. package/node_modules/@types/node/stream/promises.d.ts +83 -0
  51. package/node_modules/@types/node/stream/web.d.ts +366 -0
  52. package/node_modules/@types/node/stream.d.ts +1701 -0
  53. package/node_modules/@types/node/string_decoder.d.ts +67 -0
  54. package/node_modules/@types/node/test.d.ts +1465 -0
  55. package/node_modules/@types/node/timers/promises.d.ts +93 -0
  56. package/node_modules/@types/node/timers.d.ts +240 -0
  57. package/node_modules/@types/node/tls.d.ts +1210 -0
  58. package/node_modules/@types/node/trace_events.d.ts +182 -0
  59. package/node_modules/@types/node/ts4.8/assert/strict.d.ts +8 -0
  60. package/node_modules/@types/node/ts4.8/assert.d.ts +996 -0
  61. package/node_modules/@types/node/ts4.8/async_hooks.d.ts +539 -0
  62. package/node_modules/@types/node/ts4.8/buffer.d.ts +2362 -0
  63. package/node_modules/@types/node/ts4.8/child_process.d.ts +1540 -0
  64. package/node_modules/@types/node/ts4.8/cluster.d.ts +432 -0
  65. package/node_modules/@types/node/ts4.8/console.d.ts +415 -0
  66. package/node_modules/@types/node/ts4.8/constants.d.ts +19 -0
  67. package/node_modules/@types/node/ts4.8/crypto.d.ts +4487 -0
  68. package/node_modules/@types/node/ts4.8/dgram.d.ts +596 -0
  69. package/node_modules/@types/node/ts4.8/diagnostics_channel.d.ts +545 -0
  70. package/node_modules/@types/node/ts4.8/dns/promises.d.ts +425 -0
  71. package/node_modules/@types/node/ts4.8/dns.d.ts +809 -0
  72. package/node_modules/@types/node/ts4.8/dom-events.d.ts +122 -0
  73. package/node_modules/@types/node/ts4.8/domain.d.ts +170 -0
  74. package/node_modules/@types/node/ts4.8/events.d.ts +879 -0
  75. package/node_modules/@types/node/ts4.8/fs/promises.d.ts +1239 -0
  76. package/node_modules/@types/node/ts4.8/fs.d.ts +4311 -0
  77. package/node_modules/@types/node/ts4.8/globals.d.ts +411 -0
  78. package/node_modules/@types/node/ts4.8/globals.global.d.ts +1 -0
  79. package/node_modules/@types/node/ts4.8/http.d.ts +1887 -0
  80. package/node_modules/@types/node/ts4.8/http2.d.ts +2382 -0
  81. package/node_modules/@types/node/ts4.8/https.d.ts +550 -0
  82. package/node_modules/@types/node/ts4.8/index.d.ts +88 -0
  83. package/node_modules/@types/node/ts4.8/inspector.d.ts +2747 -0
  84. package/node_modules/@types/node/ts4.8/module.d.ts +315 -0
  85. package/node_modules/@types/node/ts4.8/net.d.ts +949 -0
  86. package/node_modules/@types/node/ts4.8/os.d.ts +478 -0
  87. package/node_modules/@types/node/ts4.8/path.d.ts +191 -0
  88. package/node_modules/@types/node/ts4.8/perf_hooks.d.ts +645 -0
  89. package/node_modules/@types/node/ts4.8/process.d.ts +1561 -0
  90. package/node_modules/@types/node/ts4.8/punycode.d.ts +117 -0
  91. package/node_modules/@types/node/ts4.8/querystring.d.ts +141 -0
  92. package/node_modules/@types/node/ts4.8/readline/promises.d.ts +150 -0
  93. package/node_modules/@types/node/ts4.8/readline.d.ts +539 -0
  94. package/node_modules/@types/node/ts4.8/repl.d.ts +430 -0
  95. package/node_modules/@types/node/ts4.8/stream/consumers.d.ts +12 -0
  96. package/node_modules/@types/node/ts4.8/stream/promises.d.ts +83 -0
  97. package/node_modules/@types/node/ts4.8/stream/web.d.ts +366 -0
  98. package/node_modules/@types/node/ts4.8/stream.d.ts +1701 -0
  99. package/node_modules/@types/node/ts4.8/string_decoder.d.ts +67 -0
  100. package/node_modules/@types/node/ts4.8/test.d.ts +1465 -0
  101. package/node_modules/@types/node/ts4.8/timers/promises.d.ts +93 -0
  102. package/node_modules/@types/node/ts4.8/timers.d.ts +240 -0
  103. package/node_modules/@types/node/ts4.8/tls.d.ts +1210 -0
  104. package/node_modules/@types/node/ts4.8/trace_events.d.ts +182 -0
  105. package/node_modules/@types/node/ts4.8/tty.d.ts +208 -0
  106. package/node_modules/@types/node/ts4.8/url.d.ts +927 -0
  107. package/node_modules/@types/node/ts4.8/util.d.ts +2183 -0
  108. package/node_modules/@types/node/ts4.8/v8.d.ts +764 -0
  109. package/node_modules/@types/node/ts4.8/vm.d.ts +903 -0
  110. package/node_modules/@types/node/ts4.8/wasi.d.ts +179 -0
  111. package/node_modules/@types/node/ts4.8/worker_threads.d.ts +691 -0
  112. package/node_modules/@types/node/ts4.8/zlib.d.ts +517 -0
  113. package/node_modules/@types/node/tty.d.ts +208 -0
  114. package/node_modules/@types/node/url.d.ts +927 -0
  115. package/node_modules/@types/node/util.d.ts +2183 -0
  116. package/node_modules/@types/node/v8.d.ts +764 -0
  117. package/node_modules/@types/node/vm.d.ts +903 -0
  118. package/node_modules/@types/node/wasi.d.ts +179 -0
  119. package/node_modules/@types/node/worker_threads.d.ts +691 -0
  120. package/node_modules/@types/node/zlib.d.ts +517 -0
  121. package/package.json +6 -6
@@ -0,0 +1,1684 @@
1
+ // Type definitions for Jest 29.2
2
+ // Project: https://jestjs.io/
3
+ // Definitions by: Asana (https://asana.com)
4
+ // Ivo Stratev <https://github.com/NoHomey>
5
+ // jwbay <https://github.com/jwbay>
6
+ // Alexey Svetliakov <https://github.com/asvetliakov>
7
+ // Alex Jover Morales <https://github.com/alexjoverm>
8
+ // Allan Lukwago <https://github.com/epicallan>
9
+ // Ika <https://github.com/ikatyang>
10
+ // Waseem Dahman <https://github.com/wsmd>
11
+ // Jamie Mason <https://github.com/JamieMason>
12
+ // Douglas Duteil <https://github.com/douglasduteil>
13
+ // Ahn <https://github.com/ahnpnl>
14
+ // Jeff Lau <https://github.com/UselessPickles>
15
+ // Andrew Makarov <https://github.com/r3nya>
16
+ // Martin Hochel <https://github.com/hotell>
17
+ // Sebastian Sebald <https://github.com/sebald>
18
+ // Andy <https://github.com/andys8>
19
+ // Antoine Brault <https://github.com/antoinebrault>
20
+ // Gregor Stamać <https://github.com/gstamac>
21
+ // ExE Boss <https://github.com/ExE-Boss>
22
+ // Alex Bolenok <https://github.com/quassnoi>
23
+ // Mario Beltrán Alarcón <https://github.com/Belco90>
24
+ // Tony Hallett <https://github.com/tonyhallett>
25
+ // Jason Yu <https://github.com/ycmjason>
26
+ // Pawel Fajfer <https://github.com/pawfa>
27
+ // Alexandre Germain <https://github.com/gerkindev>
28
+ // Adam Jones <https://github.com/domdomegg>
29
+ // Tom Mrazauskas <https://github.com/mrazauskas>
30
+ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
31
+ // Minimum TypeScript Version: 4.3
32
+
33
+ declare var beforeAll: jest.Lifecycle;
34
+ declare var beforeEach: jest.Lifecycle;
35
+ declare var afterAll: jest.Lifecycle;
36
+ declare var afterEach: jest.Lifecycle;
37
+ declare var describe: jest.Describe;
38
+ declare var fdescribe: jest.Describe;
39
+ declare var xdescribe: jest.Describe;
40
+ declare var it: jest.It;
41
+ declare var fit: jest.It;
42
+ declare var xit: jest.It;
43
+ declare var test: jest.It;
44
+ declare var xtest: jest.It;
45
+
46
+ declare const expect: jest.Expect;
47
+
48
+ type ExtractEachCallbackArgs<T extends ReadonlyArray<any>> = {
49
+ 1: [T[0]];
50
+ 2: [T[0], T[1]];
51
+ 3: [T[0], T[1], T[2]];
52
+ 4: [T[0], T[1], T[2], T[3]];
53
+ 5: [T[0], T[1], T[2], T[3], T[4]];
54
+ 6: [T[0], T[1], T[2], T[3], T[4], T[5]];
55
+ 7: [T[0], T[1], T[2], T[3], T[4], T[5], T[6]];
56
+ 8: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], T[7]];
57
+ 9: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], T[7], T[8]];
58
+ 10: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], T[7], T[8], T[9]];
59
+ fallback: Array<T extends ReadonlyArray<infer U> ? U : any>;
60
+ }[T extends Readonly<[any]>
61
+ ? 1
62
+ : T extends Readonly<[any, any]>
63
+ ? 2
64
+ : T extends Readonly<[any, any, any]>
65
+ ? 3
66
+ : T extends Readonly<[any, any, any, any]>
67
+ ? 4
68
+ : T extends Readonly<[any, any, any, any, any]>
69
+ ? 5
70
+ : T extends Readonly<[any, any, any, any, any, any]>
71
+ ? 6
72
+ : T extends Readonly<[any, any, any, any, any, any, any]>
73
+ ? 7
74
+ : T extends Readonly<[any, any, any, any, any, any, any, any]>
75
+ ? 8
76
+ : T extends Readonly<[any, any, any, any, any, any, any, any, any]>
77
+ ? 9
78
+ : T extends Readonly<[any, any, any, any, any, any, any, any, any, any]>
79
+ ? 10
80
+ : 'fallback'];
81
+
82
+ type FakeableAPI =
83
+ | 'Date'
84
+ | 'hrtime'
85
+ | 'nextTick'
86
+ | 'performance'
87
+ | 'queueMicrotask'
88
+ | 'requestAnimationFrame'
89
+ | 'cancelAnimationFrame'
90
+ | 'requestIdleCallback'
91
+ | 'cancelIdleCallback'
92
+ | 'setImmediate'
93
+ | 'clearImmediate'
94
+ | 'setInterval'
95
+ | 'clearInterval'
96
+ | 'setTimeout'
97
+ | 'clearTimeout';
98
+
99
+ interface FakeTimersConfig {
100
+ /**
101
+ * If set to `true` all timers will be advanced automatically
102
+ * by 20 milliseconds every 20 milliseconds. A custom time delta
103
+ * may be provided by passing a number.
104
+ *
105
+ * @defaultValue
106
+ * The default is `false`.
107
+ */
108
+ advanceTimers?: boolean | number;
109
+ /**
110
+ * List of names of APIs (e.g. `Date`, `nextTick()`, `setImmediate()`,
111
+ * `setTimeout()`) that should not be faked.
112
+ *
113
+ * @defaultValue
114
+ * The default is `[]`, meaning all APIs are faked.
115
+ */
116
+ doNotFake?: FakeableAPI[];
117
+ /**
118
+ * Sets current system time to be used by fake timers.
119
+ *
120
+ * @defaultValue
121
+ * The default is `Date.now()`.
122
+ */
123
+ now?: number | Date;
124
+ /**
125
+ * The maximum number of recursive timers that will be run when calling
126
+ * `jest.runAllTimers()`.
127
+ *
128
+ * @defaultValue
129
+ * The default is `100_000` timers.
130
+ */
131
+ timerLimit?: number;
132
+ /**
133
+ * Use the old fake timers implementation instead of one backed by
134
+ * [`@sinonjs/fake-timers`](https://github.com/sinonjs/fake-timers).
135
+ *
136
+ * @defaultValue
137
+ * The default is `false`.
138
+ */
139
+ legacyFakeTimers?: false;
140
+ }
141
+
142
+ interface LegacyFakeTimersConfig {
143
+ /**
144
+ * Use the old fake timers implementation instead of one backed by
145
+ * [`@sinonjs/fake-timers`](https://github.com/sinonjs/fake-timers).
146
+ *
147
+ * @defaultValue
148
+ * The default is `false`.
149
+ */
150
+ legacyFakeTimers?: true;
151
+ }
152
+
153
+ declare namespace jest {
154
+ /**
155
+ * Disables automatic mocking in the module loader.
156
+ */
157
+ function autoMockOff(): typeof jest;
158
+ /**
159
+ * Enables automatic mocking in the module loader.
160
+ */
161
+ function autoMockOn(): typeof jest;
162
+ /**
163
+ * Clears the mock.calls and mock.instances properties of all mocks.
164
+ * Equivalent to calling .mockClear() on every mocked function.
165
+ */
166
+ function clearAllMocks(): typeof jest;
167
+ /**
168
+ * Use the automatic mocking system to generate a mocked version of the given module.
169
+ */
170
+ // tslint:disable-next-line: no-unnecessary-generics
171
+ function createMockFromModule<T>(moduleName: string): T;
172
+ /**
173
+ * Resets the state of all mocks.
174
+ * Equivalent to calling .mockReset() on every mocked function.
175
+ */
176
+ function resetAllMocks(): typeof jest;
177
+ /**
178
+ * available since Jest 21.1.0
179
+ * Restores all mocks back to their original value.
180
+ * Equivalent to calling .mockRestore on every mocked function.
181
+ * Beware that jest.restoreAllMocks() only works when mock was created with
182
+ * jest.spyOn; other mocks will require you to manually restore them.
183
+ */
184
+ function restoreAllMocks(): typeof jest;
185
+ /**
186
+ * Removes any pending timers from the timer system. If any timers have
187
+ * been scheduled, they will be cleared and will never have the opportunity
188
+ * to execute in the future.
189
+ */
190
+ function clearAllTimers(): void;
191
+ /**
192
+ * Returns the number of fake timers still left to run.
193
+ */
194
+ function getTimerCount(): number;
195
+ /**
196
+ * Set the current system time used by fake timers. Simulates a user
197
+ * changing the system clock while your program is running. It affects the
198
+ * current time but it does not in itself cause e.g. timers to fire; they
199
+ * will fire exactly as they would have done without the call to
200
+ * jest.setSystemTime().
201
+ *
202
+ * > Note: This function is only available when using modern fake timers
203
+ * > implementation
204
+ */
205
+ function setSystemTime(now?: number | Date): void;
206
+ /**
207
+ * When mocking time, Date.now() will also be mocked. If you for some
208
+ * reason need access to the real current time, you can invoke this
209
+ * function.
210
+ *
211
+ * > Note: This function is only available when using modern fake timers
212
+ * > implementation
213
+ */
214
+ function getRealSystemTime(): number;
215
+ /**
216
+ * Retrieves the seed value. It will be randomly generated for each test run
217
+ * or can be manually set via the `--seed` CLI argument.
218
+ */
219
+ function getSeed(): number;
220
+ /**
221
+ * Returns the current time in ms of the fake timer clock.
222
+ */
223
+ function now(): number;
224
+ /**
225
+ * Indicates that the module system should never return a mocked version
226
+ * of the specified module, including all of the specified module's dependencies.
227
+ */
228
+ function deepUnmock(moduleName: string): typeof jest;
229
+ /**
230
+ * Disables automatic mocking in the module loader.
231
+ */
232
+ function disableAutomock(): typeof jest;
233
+ /**
234
+ * Mocks a module with an auto-mocked version when it is being required.
235
+ */
236
+ // tslint:disable-next-line no-unnecessary-generics
237
+ function doMock<T = unknown>(moduleName: string, factory?: () => T, options?: MockOptions): typeof jest;
238
+ /**
239
+ * Indicates that the module system should never return a mocked version
240
+ * of the specified module from require() (e.g. that it should always return the real module).
241
+ */
242
+ function dontMock(moduleName: string): typeof jest;
243
+ /**
244
+ * Enables automatic mocking in the module loader.
245
+ */
246
+ function enableAutomock(): typeof jest;
247
+ /**
248
+ * Creates a mock function. Optionally takes a mock implementation.
249
+ */
250
+ function fn(): Mock;
251
+ /**
252
+ * Creates a mock function. Optionally takes a mock implementation.
253
+ */
254
+ function fn<T, Y extends any[]>(implementation?: (...args: Y) => T): Mock<T, Y>;
255
+ /**
256
+ * (renamed to `createMockFromModule` in Jest 26.0.0+)
257
+ * Use the automatic mocking system to generate a mocked version of the given module.
258
+ */
259
+ // tslint:disable-next-line: no-unnecessary-generics
260
+ function genMockFromModule<T>(moduleName: string): T;
261
+ /**
262
+ * Returns whether the given function is a mock function.
263
+ */
264
+ function isMockFunction(fn: any): fn is Mock;
265
+ /**
266
+ * Mocks a module with an auto-mocked version when it is being required.
267
+ */
268
+ // tslint:disable-next-line no-unnecessary-generics
269
+ function mock<T = unknown>(moduleName: string, factory?: () => T, options?: MockOptions): typeof jest;
270
+
271
+ /**
272
+ * Wraps types of the `source` object and its deep members with type definitions
273
+ * of Jest mock function. Pass `{shallow: true}` option to disable the deeply
274
+ * mocked behavior.
275
+ */
276
+ function mocked<T>(source: T, options?: { shallow: false }): MaybeMockedDeep<T>;
277
+ /**
278
+ * Wraps types of the `source` object with type definitions of Jest mock function.
279
+ */
280
+ function mocked<T>(source: T, options: { shallow: true }): MaybeMocked<T>;
281
+ /**
282
+ * Returns the actual module instead of a mock, bypassing all checks on
283
+ * whether the module should receive a mock implementation or not.
284
+ */
285
+ // tslint:disable-next-line: no-unnecessary-generics
286
+ function requireActual<TModule extends {} = any>(moduleName: string): TModule;
287
+ /**
288
+ * Returns a mock module instead of the actual module, bypassing all checks
289
+ * on whether the module should be required normally or not.
290
+ */
291
+ // tslint:disable-next-line: no-unnecessary-generics
292
+ function requireMock<TModule extends {} = any>(moduleName: string): TModule;
293
+ /**
294
+ * Resets the module registry - the cache of all required modules. This is
295
+ * useful to isolate modules where local state might conflict between tests.
296
+ */
297
+ function resetModules(): typeof jest;
298
+ /**
299
+ * Creates a sandbox registry for the modules that are loaded inside the callback function..
300
+ * This is useful to isolate specific modules for every test so that local module state doesn't conflict between tests.
301
+ */
302
+ function isolateModules(fn: () => void): typeof jest;
303
+ /**
304
+ * Runs failed tests n-times until they pass or until the max number of retries is exhausted.
305
+ * This only works with jest-circus!
306
+ */
307
+ function retryTimes(numRetries: number, options?: { logErrorsBeforeRetry?: boolean }): typeof jest;
308
+ /**
309
+ * Exhausts tasks queued by setImmediate().
310
+ * > Note: This function is only available when using modern fake timers
311
+ * > implementation
312
+ */
313
+ function runAllImmediates(): void;
314
+ /**
315
+ * Exhausts the micro-task queue (usually interfaced in node via process.nextTick).
316
+ */
317
+ function runAllTicks(): void;
318
+ /**
319
+ * Exhausts both the macro-task queue (i.e., all tasks queued by setTimeout(),
320
+ * setInterval(), and setImmediate()) and the micro-task queue (usually interfaced
321
+ * in node via process.nextTick).
322
+ */
323
+ function runAllTimers(): void;
324
+ /**
325
+ * Executes only the macro-tasks that are currently pending (i.e., only the
326
+ * tasks that have been queued by setTimeout() or setInterval() up to this point).
327
+ * If any of the currently pending macro-tasks schedule new macro-tasks,
328
+ * those new tasks will not be executed by this call.
329
+ */
330
+ function runOnlyPendingTimers(): void;
331
+ /**
332
+ * Advances all timers by msToRun milliseconds. All pending "macro-tasks" that have been
333
+ * queued via setTimeout() or setInterval(), and would be executed within this timeframe
334
+ * will be executed.
335
+ */
336
+ function advanceTimersByTime(msToRun: number): void;
337
+ /**
338
+ * Advances all timers by the needed milliseconds so that only the next
339
+ * timeouts/intervals will run. Optionally, you can provide steps, so it
340
+ * will run steps amount of next timeouts/intervals.
341
+ */
342
+ function advanceTimersToNextTimer(step?: number): void;
343
+ /**
344
+ * Explicitly supplies the mock object that the module system should return
345
+ * for the specified module.
346
+ */
347
+ // tslint:disable-next-line: no-unnecessary-generics
348
+ function setMock<T>(moduleName: string, moduleExports: T): typeof jest;
349
+ /**
350
+ * Set the default timeout interval for tests and before/after hooks in milliseconds.
351
+ * Note: The default timeout interval is 5 seconds if this method is not called.
352
+ */
353
+ function setTimeout(timeout: number): typeof jest;
354
+ /**
355
+ * Creates a mock function similar to jest.fn but also tracks calls to `object[methodName]`
356
+ *
357
+ * Note: By default, jest.spyOn also calls the spied method. This is different behavior from most
358
+ * other test libraries.
359
+ *
360
+ * @example
361
+ *
362
+ * const video = require('./video');
363
+ *
364
+ * test('plays video', () => {
365
+ * const spy = jest.spyOn(video, 'play');
366
+ * const isPlaying = video.play();
367
+ *
368
+ * expect(spy).toHaveBeenCalled();
369
+ * expect(isPlaying).toBe(true);
370
+ *
371
+ * spy.mockReset();
372
+ * spy.mockRestore();
373
+ * });
374
+ */
375
+ function spyOn<
376
+ T extends {},
377
+ Key extends keyof T,
378
+ A extends PropertyAccessors<Key, T> = PropertyAccessors<Key, T>,
379
+ Value extends Required<T>[Key] = Required<T>[Key],
380
+ >(
381
+ object: T,
382
+ method: Key,
383
+ accessType: A,
384
+ ): A extends SetAccessor
385
+ ? SpyInstance<void, [Value]>
386
+ : A extends GetAccessor
387
+ ? SpyInstance<Value, []>
388
+ : Value extends Constructor
389
+ ? SpyInstance<InstanceType<Value>, ConstructorArgsType<Value>>
390
+ : Value extends Func
391
+ ? SpyInstance<ReturnType<Value>, ArgsType<Value>>
392
+ : never;
393
+ function spyOn<T extends {}, M extends ConstructorPropertyNames<Required<T>>>(
394
+ object: T,
395
+ method: M,
396
+ ): ConstructorProperties<Required<T>>[M] extends new (...args: any[]) => any
397
+ ? SpyInstance<
398
+ InstanceType<ConstructorProperties<Required<T>>[M]>,
399
+ ConstructorArgsType<ConstructorProperties<Required<T>>[M]>
400
+ >
401
+ : never;
402
+ function spyOn<T extends {}, M extends FunctionPropertyNames<Required<T>>>(
403
+ object: T,
404
+ method: M,
405
+ ): FunctionProperties<Required<T>>[M] extends Func
406
+ ? SpyInstance<ReturnType<FunctionProperties<Required<T>>[M]>, ArgsType<FunctionProperties<Required<T>>[M]>>
407
+ : never;
408
+ /**
409
+ * Indicates that the module system should never return a mocked version of
410
+ * the specified module from require() (e.g. that it should always return the real module).
411
+ */
412
+ function unmock(moduleName: string): typeof jest;
413
+ /**
414
+ * Instructs Jest to use fake versions of the standard timer functions.
415
+ */
416
+ function useFakeTimers(config?: FakeTimersConfig | LegacyFakeTimersConfig): typeof jest;
417
+ /**
418
+ * Instructs Jest to use the real versions of the standard timer functions.
419
+ */
420
+ function useRealTimers(): typeof jest;
421
+
422
+ interface MockOptions {
423
+ virtual?: boolean | undefined;
424
+ }
425
+
426
+ type MockableFunction = (...args: any[]) => any;
427
+ type MethodKeysOf<T> = { [K in keyof T]: T[K] extends MockableFunction ? K : never }[keyof T];
428
+ type PropertyKeysOf<T> = { [K in keyof T]: T[K] extends MockableFunction ? never : K }[keyof T];
429
+ type ArgumentsOf<T> = T extends (...args: infer A) => any ? A : never;
430
+ type ConstructorArgumentsOf<T> = T extends new (...args: infer A) => any ? A : never;
431
+
432
+ interface MockWithArgs<T extends MockableFunction> extends MockInstance<ReturnType<T>, ArgumentsOf<T>> {
433
+ new (...args: ConstructorArgumentsOf<T>): T;
434
+ (...args: ArgumentsOf<T>): ReturnType<T>;
435
+ }
436
+ type MaybeMockedConstructor<T> = T extends new (...args: any[]) => infer R
437
+ ? MockInstance<R, ConstructorArgumentsOf<T>>
438
+ : T;
439
+ type MockedFn<T extends MockableFunction> = MockWithArgs<T> & { [K in keyof T]: T[K] };
440
+ type MockedFunctionDeep<T extends MockableFunction> = MockWithArgs<T> & MockedObjectDeep<T>;
441
+ type MockedObject<T> = MaybeMockedConstructor<T> & {
442
+ [K in MethodKeysOf<T>]: T[K] extends MockableFunction ? MockedFn<T[K]> : T[K];
443
+ } & { [K in PropertyKeysOf<T>]: T[K] };
444
+ type MockedObjectDeep<T> = MaybeMockedConstructor<T> & {
445
+ [K in MethodKeysOf<T>]: T[K] extends MockableFunction ? MockedFunctionDeep<T[K]> : T[K];
446
+ } & { [K in PropertyKeysOf<T>]: MaybeMockedDeep<T[K]> };
447
+ type MaybeMockedDeep<T> = T extends MockableFunction
448
+ ? MockedFunctionDeep<T>
449
+ : T extends object // eslint-disable-line @typescript-eslint/ban-types
450
+ ? MockedObjectDeep<T>
451
+ : T;
452
+ // eslint-disable-next-line @typescript-eslint/ban-types
453
+ type MaybeMocked<T> = T extends MockableFunction ? MockedFn<T> : T extends object ? MockedObject<T> : T;
454
+ type EmptyFunction = () => void;
455
+ type ArgsType<T> = T extends (...args: infer A) => any ? A : never;
456
+ type Constructor = new (...args: any[]) => any;
457
+ type Func = (...args: any[]) => any;
458
+ type ConstructorArgsType<T> = T extends new (...args: infer A) => any ? A : never;
459
+ type RejectedValue<T> = T extends PromiseLike<any> ? any : never;
460
+ type ResolvedValue<T> = T extends PromiseLike<infer U> ? U | T : never;
461
+ // see https://github.com/Microsoft/TypeScript/issues/25215
462
+ type NonFunctionPropertyNames<T> = keyof { [K in keyof T as T[K] extends Func ? never : K]: T[K] };
463
+ type GetAccessor = 'get';
464
+ type SetAccessor = 'set';
465
+ type PropertyAccessors<M extends keyof T, T extends {}> = M extends NonFunctionPropertyNames<Required<T>>
466
+ ? GetAccessor | SetAccessor
467
+ : never;
468
+ type FunctionProperties<T> = { [K in keyof T as T[K] extends (...args: any[]) => any ? K : never]: T[K] };
469
+ type FunctionPropertyNames<T> = keyof FunctionProperties<T>;
470
+ type RemoveIndex<T> = {
471
+ // from https://stackoverflow.com/a/66252656/4536543
472
+ [P in keyof T as string extends P ? never : number extends P ? never : P]: T[P];
473
+ };
474
+ type ConstructorProperties<T> = {
475
+ [K in keyof RemoveIndex<T> as RemoveIndex<T>[K] extends Constructor ? K : never]: RemoveIndex<T>[K];
476
+ };
477
+ type ConstructorPropertyNames<T> = RemoveIndex<keyof ConstructorProperties<T>>;
478
+
479
+ interface DoneCallback {
480
+ (...args: any[]): any;
481
+ fail(error?: string | { message: string }): any;
482
+ }
483
+
484
+ type ProvidesCallback = ((cb: DoneCallback) => void | undefined) | (() => Promise<unknown>);
485
+ type ProvidesHookCallback = (() => any) | ProvidesCallback;
486
+
487
+ type Lifecycle = (fn: ProvidesHookCallback, timeout?: number) => any;
488
+
489
+ interface FunctionLike {
490
+ readonly name: string;
491
+ }
492
+
493
+ interface Each {
494
+ // Exclusively arrays.
495
+ <T extends any[] | [any]>(cases: ReadonlyArray<T>): (
496
+ name: string,
497
+ fn: (...args: T) => any,
498
+ timeout?: number,
499
+ ) => void;
500
+ <T extends ReadonlyArray<any>>(cases: ReadonlyArray<T>): (
501
+ name: string,
502
+ fn: (...args: ExtractEachCallbackArgs<T>) => any,
503
+ timeout?: number,
504
+ ) => void;
505
+ // Not arrays.
506
+ <T>(cases: ReadonlyArray<T>): (name: string, fn: (...args: T[]) => any, timeout?: number) => void;
507
+ (cases: ReadonlyArray<ReadonlyArray<any>>): (
508
+ name: string,
509
+ fn: (...args: any[]) => any,
510
+ timeout?: number,
511
+ ) => void;
512
+ (strings: TemplateStringsArray, ...placeholders: any[]): (
513
+ name: string,
514
+ fn: (arg: any) => any,
515
+ timeout?: number,
516
+ ) => void;
517
+ }
518
+
519
+ /**
520
+ * Creates a test closure
521
+ */
522
+ interface It {
523
+ /**
524
+ * Creates a test closure.
525
+ *
526
+ * @param name The name of your test
527
+ * @param fn The function for your test
528
+ * @param timeout The timeout for an async function test
529
+ */
530
+ (name: string, fn?: ProvidesCallback, timeout?: number): void;
531
+ /**
532
+ * Only runs this test in the current file.
533
+ */
534
+ only: It;
535
+ /**
536
+ * Mark this test as expecting to fail.
537
+ *
538
+ * Only available in the default `jest-circus` runner.
539
+ */
540
+ failing: It;
541
+ /**
542
+ * Skips running this test in the current file.
543
+ */
544
+ skip: It;
545
+ /**
546
+ * Sketch out which tests to write in the future.
547
+ */
548
+ todo: It;
549
+ /**
550
+ * Experimental and should be avoided.
551
+ */
552
+ concurrent: It;
553
+ /**
554
+ * Use if you keep duplicating the same test with different data. `.each` allows you to write the
555
+ * test once and pass data in.
556
+ *
557
+ * `.each` is available with two APIs:
558
+ *
559
+ * #### 1 `test.each(table)(name, fn)`
560
+ *
561
+ * - `table`: Array of Arrays with the arguments that are passed into the test fn for each row.
562
+ * - `name`: String the title of the test block.
563
+ * - `fn`: Function the test to be ran, this is the function that will receive the parameters in each row as function arguments.
564
+ *
565
+ *
566
+ * #### 2 `test.each table(name, fn)`
567
+ *
568
+ * - `table`: Tagged Template Literal
569
+ * - `name`: String the title of the test, use `$variable` to inject test data into the test title from the tagged template expressions.
570
+ * - `fn`: Function the test to be ran, this is the function that will receive the test data object..
571
+ *
572
+ * @example
573
+ *
574
+ * // API 1
575
+ * test.each([[1, 1, 2], [1, 2, 3], [2, 1, 3]])(
576
+ * '.add(%i, %i)',
577
+ * (a, b, expected) => {
578
+ * expect(a + b).toBe(expected);
579
+ * },
580
+ * );
581
+ *
582
+ * // API 2
583
+ * test.each`
584
+ * a | b | expected
585
+ * ${1} | ${1} | ${2}
586
+ * ${1} | ${2} | ${3}
587
+ * ${2} | ${1} | ${3}
588
+ * `('returns $expected when $a is added $b', ({a, b, expected}) => {
589
+ * expect(a + b).toBe(expected);
590
+ * });
591
+ *
592
+ */
593
+ each: Each;
594
+ }
595
+
596
+ interface Describe {
597
+ // tslint:disable-next-line ban-types
598
+ (name: number | string | Function | FunctionLike, fn: EmptyFunction): void;
599
+ /** Only runs the tests inside this `describe` for the current file */
600
+ only: Describe;
601
+ /** Skips running the tests inside this `describe` for the current file */
602
+ skip: Describe;
603
+ each: Each;
604
+ }
605
+
606
+ type EqualityTester = (a: any, b: any) => boolean | undefined;
607
+
608
+ type MatcherUtils = import('expect').MatcherUtils & { [other: string]: any };
609
+
610
+ interface ExpectExtendMap {
611
+ [key: string]: CustomMatcher;
612
+ }
613
+
614
+ type MatcherContext = MatcherUtils & Readonly<MatcherState>;
615
+ type CustomMatcher = (
616
+ this: MatcherContext,
617
+ received: any,
618
+ ...actual: any[]
619
+ ) => CustomMatcherResult | Promise<CustomMatcherResult>;
620
+
621
+ interface CustomMatcherResult {
622
+ pass: boolean;
623
+ message: () => string;
624
+ }
625
+
626
+ type SnapshotSerializerPlugin = import('pretty-format').Plugin;
627
+
628
+ interface InverseAsymmetricMatchers {
629
+ /**
630
+ * `expect.not.arrayContaining(array)` matches a received array which
631
+ * does not contain all of the elements in the expected array. That is,
632
+ * the expected array is not a subset of the received array. It is the
633
+ * inverse of `expect.arrayContaining`.
634
+ *
635
+ * Optionally, you can provide a type for the elements via a generic.
636
+ */
637
+ // tslint:disable-next-line: no-unnecessary-generics
638
+ arrayContaining<E = any>(arr: E[]): any;
639
+ /**
640
+ * `expect.not.objectContaining(object)` matches any received object
641
+ * that does not recursively match the expected properties. That is, the
642
+ * expected object is not a subset of the received object. Therefore,
643
+ * it matches a received object which contains properties that are not
644
+ * in the expected object. It is the inverse of `expect.objectContaining`.
645
+ *
646
+ * Optionally, you can provide a type for the object via a generic.
647
+ * This ensures that the object contains the desired structure.
648
+ */
649
+ // tslint:disable-next-line: no-unnecessary-generics
650
+ objectContaining<E = {}>(obj: E): any;
651
+ /**
652
+ * `expect.not.stringMatching(string | regexp)` matches the received
653
+ * string that does not match the expected regexp. It is the inverse of
654
+ * `expect.stringMatching`.
655
+ */
656
+ stringMatching(str: string | RegExp): any;
657
+ /**
658
+ * `expect.not.stringContaining(string)` matches the received string
659
+ * that does not contain the exact expected string. It is the inverse of
660
+ * `expect.stringContaining`.
661
+ */
662
+ stringContaining(str: string): any;
663
+ }
664
+ type MatcherState = import('expect').MatcherState;
665
+ /**
666
+ * The `expect` function is used every time you want to test a value.
667
+ * You will rarely call `expect` by itself.
668
+ */
669
+ interface Expect {
670
+ /**
671
+ * The `expect` function is used every time you want to test a value.
672
+ * You will rarely call `expect` by itself.
673
+ *
674
+ * @param actual The value to apply matchers against.
675
+ */
676
+ <T = any>(actual: T): JestMatchers<T>;
677
+ /**
678
+ * Matches anything but null or undefined. You can use it inside `toEqual` or `toBeCalledWith` instead
679
+ * of a literal value. For example, if you want to check that a mock function is called with a
680
+ * non-null argument:
681
+ *
682
+ * @example
683
+ *
684
+ * test('map calls its argument with a non-null argument', () => {
685
+ * const mock = jest.fn();
686
+ * [1].map(x => mock(x));
687
+ * expect(mock).toBeCalledWith(expect.anything());
688
+ * });
689
+ *
690
+ */
691
+ anything(): any;
692
+ /**
693
+ * Matches anything that was created with the given constructor.
694
+ * You can use it inside `toEqual` or `toBeCalledWith` instead of a literal value.
695
+ *
696
+ * @example
697
+ *
698
+ * function randocall(fn) {
699
+ * return fn(Math.floor(Math.random() * 6 + 1));
700
+ * }
701
+ *
702
+ * test('randocall calls its callback with a number', () => {
703
+ * const mock = jest.fn();
704
+ * randocall(mock);
705
+ * expect(mock).toBeCalledWith(expect.any(Number));
706
+ * });
707
+ */
708
+ any<T extends Constructor>(classType: T): T extends Func ? ReturnType<T> : InstanceType<T>;
709
+ /**
710
+ * Matches any array made up entirely of elements in the provided array.
711
+ * You can use it inside `toEqual` or `toBeCalledWith` instead of a literal value.
712
+ *
713
+ * Optionally, you can provide a type for the elements via a generic.
714
+ */
715
+ // tslint:disable-next-line: no-unnecessary-generics
716
+ arrayContaining<E = any>(arr: E[]): any;
717
+ /**
718
+ * Verifies that a certain number of assertions are called during a test.
719
+ * This is often useful when testing asynchronous code, in order to
720
+ * make sure that assertions in a callback actually got called.
721
+ */
722
+ assertions(num: number): void;
723
+ /**
724
+ * Useful when comparing floating point numbers in object properties or array item.
725
+ * If you need to compare a number, use `.toBeCloseTo` instead.
726
+ *
727
+ * The optional `numDigits` argument limits the number of digits to check after the decimal point.
728
+ * For the default value 2, the test criterion is `Math.abs(expected - received) < 0.005` (that is, `10 ** -2 / 2`).
729
+ */
730
+ closeTo(num: number, numDigits?: number): any;
731
+ /**
732
+ * Verifies that at least one assertion is called during a test.
733
+ * This is often useful when testing asynchronous code, in order to
734
+ * make sure that assertions in a callback actually got called.
735
+ */
736
+ hasAssertions(): void;
737
+ /**
738
+ * You can use `expect.extend` to add your own matchers to Jest.
739
+ */
740
+ extend(obj: ExpectExtendMap): void;
741
+ /**
742
+ * Adds a module to format application-specific data structures for serialization.
743
+ */
744
+ addSnapshotSerializer(serializer: SnapshotSerializerPlugin): void;
745
+ /**
746
+ * Matches any object that recursively matches the provided keys.
747
+ * This is often handy in conjunction with other asymmetric matchers.
748
+ *
749
+ * Optionally, you can provide a type for the object via a generic.
750
+ * This ensures that the object contains the desired structure.
751
+ */
752
+ // tslint:disable-next-line: no-unnecessary-generics
753
+ objectContaining<E = {}>(obj: E): any;
754
+ /**
755
+ * Matches any string that contains the exact provided string
756
+ */
757
+ stringMatching(str: string | RegExp): any;
758
+ /**
759
+ * Matches any received string that contains the exact expected string
760
+ */
761
+ stringContaining(str: string): any;
762
+
763
+ not: InverseAsymmetricMatchers;
764
+
765
+ setState(state: object): void;
766
+ getState(): MatcherState & Record<string, any>;
767
+ }
768
+
769
+ type JestMatchers<T> = JestMatchersShape<Matchers<void, T>, Matchers<Promise<void>, T>>;
770
+
771
+ type JestMatchersShape<TNonPromise extends {} = {}, TPromise extends {} = {}> = {
772
+ /**
773
+ * Use resolves to unwrap the value of a fulfilled promise so any other
774
+ * matcher can be chained. If the promise is rejected the assertion fails.
775
+ */
776
+ resolves: AndNot<TPromise>;
777
+ /**
778
+ * Unwraps the reason of a rejected promise so any other matcher can be chained.
779
+ * If the promise is fulfilled the assertion fails.
780
+ */
781
+ rejects: AndNot<TPromise>;
782
+ } & AndNot<TNonPromise>;
783
+ type AndNot<T> = T & {
784
+ not: T;
785
+ };
786
+
787
+ // should be R extends void|Promise<void> but getting dtslint error
788
+ interface Matchers<R, T = {}> {
789
+ /**
790
+ * Ensures the last call to a mock function was provided specific args.
791
+ *
792
+ * Optionally, you can provide a type for the expected arguments via a generic.
793
+ * Note that the type must be either an array or a tuple.
794
+ */
795
+ // tslint:disable-next-line: no-unnecessary-generics
796
+ lastCalledWith<E extends any[]>(...args: E): R;
797
+ /**
798
+ * Ensure that the last call to a mock function has returned a specified value.
799
+ *
800
+ * Optionally, you can provide a type for the expected value via a generic.
801
+ * This is particularly useful for ensuring expected objects have the right structure.
802
+ */
803
+ // tslint:disable-next-line: no-unnecessary-generics
804
+ lastReturnedWith<E = any>(expected?: E): R;
805
+ /**
806
+ * Ensure that a mock function is called with specific arguments on an Nth call.
807
+ *
808
+ * Optionally, you can provide a type for the expected arguments via a generic.
809
+ * Note that the type must be either an array or a tuple.
810
+ */
811
+ // tslint:disable-next-line: no-unnecessary-generics
812
+ nthCalledWith<E extends any[]>(nthCall: number, ...params: E): R;
813
+ /**
814
+ * Ensure that the nth call to a mock function has returned a specified value.
815
+ *
816
+ * Optionally, you can provide a type for the expected value via a generic.
817
+ * This is particularly useful for ensuring expected objects have the right structure.
818
+ */
819
+ // tslint:disable-next-line: no-unnecessary-generics
820
+ nthReturnedWith<E = any>(n: number, expected?: E): R;
821
+ /**
822
+ * Checks that a value is what you expect. It uses `Object.is` to check strict equality.
823
+ * Don't use `toBe` with floating-point numbers.
824
+ *
825
+ * Optionally, you can provide a type for the expected value via a generic.
826
+ * This is particularly useful for ensuring expected objects have the right structure.
827
+ */
828
+ // tslint:disable-next-line: no-unnecessary-generics
829
+ toBe<E = any>(expected: E): R;
830
+ /**
831
+ * Ensures that a mock function is called.
832
+ */
833
+ toBeCalled(): R;
834
+ /**
835
+ * Ensures that a mock function is called an exact number of times.
836
+ */
837
+ toBeCalledTimes(expected: number): R;
838
+ /**
839
+ * Ensure that a mock function is called with specific arguments.
840
+ *
841
+ * Optionally, you can provide a type for the expected arguments via a generic.
842
+ * Note that the type must be either an array or a tuple.
843
+ */
844
+ // tslint:disable-next-line: no-unnecessary-generics
845
+ toBeCalledWith<E extends any[]>(...args: E): R;
846
+ /**
847
+ * Using exact equality with floating point numbers is a bad idea.
848
+ * Rounding means that intuitive things fail.
849
+ * The default for numDigits is 2.
850
+ */
851
+ toBeCloseTo(expected: number, numDigits?: number): R;
852
+ /**
853
+ * Ensure that a variable is not undefined.
854
+ */
855
+ toBeDefined(): R;
856
+ /**
857
+ * When you don't care what a value is, you just want to
858
+ * ensure a value is false in a boolean context.
859
+ */
860
+ toBeFalsy(): R;
861
+ /**
862
+ * For comparing floating point or big integer numbers.
863
+ */
864
+ toBeGreaterThan(expected: number | bigint): R;
865
+ /**
866
+ * For comparing floating point or big integer numbers.
867
+ */
868
+ toBeGreaterThanOrEqual(expected: number | bigint): R;
869
+ /**
870
+ * Ensure that an object is an instance of a class.
871
+ * This matcher uses `instanceof` underneath.
872
+ *
873
+ * Optionally, you can provide a type for the expected value via a generic.
874
+ * This is particularly useful for ensuring expected objects have the right structure.
875
+ */
876
+ // tslint:disable-next-line: no-unnecessary-generics
877
+ toBeInstanceOf<E = any>(expected: E): R;
878
+ /**
879
+ * For comparing floating point or big integer numbers.
880
+ */
881
+ toBeLessThan(expected: number | bigint): R;
882
+ /**
883
+ * For comparing floating point or big integer numbers.
884
+ */
885
+ toBeLessThanOrEqual(expected: number | bigint): R;
886
+ /**
887
+ * This is the same as `.toBe(null)` but the error messages are a bit nicer.
888
+ * So use `.toBeNull()` when you want to check that something is null.
889
+ */
890
+ toBeNull(): R;
891
+ /**
892
+ * Use when you don't care what a value is, you just want to ensure a value
893
+ * is true in a boolean context. In JavaScript, there are six falsy values:
894
+ * `false`, `0`, `''`, `null`, `undefined`, and `NaN`. Everything else is truthy.
895
+ */
896
+ toBeTruthy(): R;
897
+ /**
898
+ * Used to check that a variable is undefined.
899
+ */
900
+ toBeUndefined(): R;
901
+ /**
902
+ * Used to check that a variable is NaN.
903
+ */
904
+ toBeNaN(): R;
905
+ /**
906
+ * Used when you want to check that an item is in a list.
907
+ * For testing the items in the list, this uses `===`, a strict equality check.
908
+ * It can also check whether a string is a substring of another string.
909
+ *
910
+ * Optionally, you can provide a type for the expected value via a generic.
911
+ * This is particularly useful for ensuring expected objects have the right structure.
912
+ */
913
+ // tslint:disable-next-line: no-unnecessary-generics
914
+ toContain<E = any>(expected: E): R;
915
+ /**
916
+ * Used when you want to check that an item is in a list.
917
+ * For testing the items in the list, this matcher recursively checks the
918
+ * equality of all fields, rather than checking for object identity.
919
+ *
920
+ * Optionally, you can provide a type for the expected value via a generic.
921
+ * This is particularly useful for ensuring expected objects have the right structure.
922
+ */
923
+ // tslint:disable-next-line: no-unnecessary-generics
924
+ toContainEqual<E = any>(expected: E): R;
925
+ /**
926
+ * Used when you want to check that two objects have the same value.
927
+ * This matcher recursively checks the equality of all fields, rather than checking for object identity.
928
+ *
929
+ * Optionally, you can provide a type for the expected value via a generic.
930
+ * This is particularly useful for ensuring expected objects have the right structure.
931
+ */
932
+ // tslint:disable-next-line: no-unnecessary-generics
933
+ toEqual<E = any>(expected: E): R;
934
+ /**
935
+ * Ensures that a mock function is called.
936
+ */
937
+ toHaveBeenCalled(): R;
938
+ /**
939
+ * Ensures that a mock function is called an exact number of times.
940
+ */
941
+ toHaveBeenCalledTimes(expected: number): R;
942
+ /**
943
+ * Ensure that a mock function is called with specific arguments.
944
+ *
945
+ * Optionally, you can provide a type for the expected arguments via a generic.
946
+ * Note that the type must be either an array or a tuple.
947
+ */
948
+ // tslint:disable-next-line: no-unnecessary-generics
949
+ toHaveBeenCalledWith<E extends any[]>(...params: E): R;
950
+ /**
951
+ * Ensure that a mock function is called with specific arguments on an Nth call.
952
+ *
953
+ * Optionally, you can provide a type for the expected arguments via a generic.
954
+ * Note that the type must be either an array or a tuple.
955
+ */
956
+ // tslint:disable-next-line: no-unnecessary-generics
957
+ toHaveBeenNthCalledWith<E extends any[]>(nthCall: number, ...params: E): R;
958
+ /**
959
+ * If you have a mock function, you can use `.toHaveBeenLastCalledWith`
960
+ * to test what arguments it was last called with.
961
+ *
962
+ * Optionally, you can provide a type for the expected arguments via a generic.
963
+ * Note that the type must be either an array or a tuple.
964
+ */
965
+ // tslint:disable-next-line: no-unnecessary-generics
966
+ toHaveBeenLastCalledWith<E extends any[]>(...params: E): R;
967
+ /**
968
+ * Use to test the specific value that a mock function last returned.
969
+ * If the last call to the mock function threw an error, then this matcher will fail
970
+ * no matter what value you provided as the expected return value.
971
+ *
972
+ * Optionally, you can provide a type for the expected value via a generic.
973
+ * This is particularly useful for ensuring expected objects have the right structure.
974
+ */
975
+ // tslint:disable-next-line: no-unnecessary-generics
976
+ toHaveLastReturnedWith<E = any>(expected?: E): R;
977
+ /**
978
+ * Used to check that an object has a `.length` property
979
+ * and it is set to a certain numeric value.
980
+ */
981
+ toHaveLength(expected: number): R;
982
+ /**
983
+ * Use to test the specific value that a mock function returned for the nth call.
984
+ * If the nth call to the mock function threw an error, then this matcher will fail
985
+ * no matter what value you provided as the expected return value.
986
+ *
987
+ * Optionally, you can provide a type for the expected value via a generic.
988
+ * This is particularly useful for ensuring expected objects have the right structure.
989
+ */
990
+ // tslint:disable-next-line: no-unnecessary-generics
991
+ toHaveNthReturnedWith<E = any>(nthCall: number, expected?: E): R;
992
+ /**
993
+ * Use to check if property at provided reference keyPath exists for an object.
994
+ * For checking deeply nested properties in an object you may use dot notation or an array containing
995
+ * the keyPath for deep references.
996
+ *
997
+ * Optionally, you can provide a value to check if it's equal to the value present at keyPath
998
+ * on the target object. This matcher uses 'deep equality' (like `toEqual()`) and recursively checks
999
+ * the equality of all fields.
1000
+ *
1001
+ * @example
1002
+ *
1003
+ * expect(houseForSale).toHaveProperty('kitchen.area', 20);
1004
+ */
1005
+ // tslint:disable-next-line: no-unnecessary-generics
1006
+ toHaveProperty<E = any>(propertyPath: string | any[], value?: E): R;
1007
+ /**
1008
+ * Use to test that the mock function successfully returned (i.e., did not throw an error) at least one time
1009
+ */
1010
+ toHaveReturned(): R;
1011
+ /**
1012
+ * Use to ensure that a mock function returned successfully (i.e., did not throw an error) an exact number of times.
1013
+ * Any calls to the mock function that throw an error are not counted toward the number of times the function returned.
1014
+ */
1015
+ toHaveReturnedTimes(expected: number): R;
1016
+ /**
1017
+ * Use to ensure that a mock function returned a specific value.
1018
+ *
1019
+ * Optionally, you can provide a type for the expected value via a generic.
1020
+ * This is particularly useful for ensuring expected objects have the right structure.
1021
+ */
1022
+ // tslint:disable-next-line: no-unnecessary-generics
1023
+ toHaveReturnedWith<E = any>(expected?: E): R;
1024
+ /**
1025
+ * Check that a string matches a regular expression.
1026
+ */
1027
+ toMatch(expected: string | RegExp): R;
1028
+ /**
1029
+ * Used to check that a JavaScript object matches a subset of the properties of an object
1030
+ *
1031
+ * Optionally, you can provide an object to use as Generic type for the expected value.
1032
+ * This ensures that the matching object matches the structure of the provided object-like type.
1033
+ *
1034
+ * @example
1035
+ *
1036
+ * type House = {
1037
+ * bath: boolean;
1038
+ * bedrooms: number;
1039
+ * kitchen: {
1040
+ * amenities: string[];
1041
+ * area: number;
1042
+ * wallColor: string;
1043
+ * }
1044
+ * };
1045
+ *
1046
+ * expect(desiredHouse).toMatchObject<House>({...standardHouse, kitchen: {area: 20}}) // wherein standardHouse is some base object of type House
1047
+ */
1048
+ // tslint:disable-next-line: no-unnecessary-generics
1049
+ toMatchObject<E extends {} | any[]>(expected: E): R;
1050
+ /**
1051
+ * This ensures that a value matches the most recent snapshot with property matchers.
1052
+ * Check out [the Snapshot Testing guide](http://facebook.github.io/jest/docs/snapshot-testing.html) for more information.
1053
+ */
1054
+ // tslint:disable-next-line: no-unnecessary-generics
1055
+ toMatchSnapshot<U extends { [P in keyof T]: any }>(propertyMatchers: Partial<U>, snapshotName?: string): R;
1056
+ /**
1057
+ * This ensures that a value matches the most recent snapshot.
1058
+ * Check out [the Snapshot Testing guide](http://facebook.github.io/jest/docs/snapshot-testing.html) for more information.
1059
+ */
1060
+ toMatchSnapshot(snapshotName?: string): R;
1061
+ /**
1062
+ * This ensures that a value matches the most recent snapshot with property matchers.
1063
+ * Instead of writing the snapshot value to a .snap file, it will be written into the source code automatically.
1064
+ * Check out [the Snapshot Testing guide](http://facebook.github.io/jest/docs/snapshot-testing.html) for more information.
1065
+ */
1066
+ // tslint:disable-next-line: no-unnecessary-generics
1067
+ toMatchInlineSnapshot<U extends { [P in keyof T]: any }>(propertyMatchers: Partial<U>, snapshot?: string): R;
1068
+ /**
1069
+ * This ensures that a value matches the most recent snapshot with property matchers.
1070
+ * Instead of writing the snapshot value to a .snap file, it will be written into the source code automatically.
1071
+ * Check out [the Snapshot Testing guide](http://facebook.github.io/jest/docs/snapshot-testing.html) for more information.
1072
+ */
1073
+ toMatchInlineSnapshot(snapshot?: string): R;
1074
+ /**
1075
+ * Ensure that a mock function has returned (as opposed to thrown) at least once.
1076
+ */
1077
+ toReturn(): R;
1078
+ /**
1079
+ * Ensure that a mock function has returned (as opposed to thrown) a specified number of times.
1080
+ */
1081
+ toReturnTimes(count: number): R;
1082
+ /**
1083
+ * Ensure that a mock function has returned a specified value at least once.
1084
+ *
1085
+ * Optionally, you can provide a type for the expected value via a generic.
1086
+ * This is particularly useful for ensuring expected objects have the right structure.
1087
+ */
1088
+ // tslint:disable-next-line: no-unnecessary-generics
1089
+ toReturnWith<E = any>(value?: E): R;
1090
+ /**
1091
+ * Use to test that objects have the same types as well as structure.
1092
+ *
1093
+ * Optionally, you can provide a type for the expected value via a generic.
1094
+ * This is particularly useful for ensuring expected objects have the right structure.
1095
+ */
1096
+ // tslint:disable-next-line: no-unnecessary-generics
1097
+ toStrictEqual<E = any>(expected: E): R;
1098
+ /**
1099
+ * Used to test that a function throws when it is called.
1100
+ */
1101
+ toThrow(error?: string | Constructable | RegExp | Error): R;
1102
+ /**
1103
+ * If you want to test that a specific error is thrown inside a function.
1104
+ */
1105
+ toThrowError(error?: string | Constructable | RegExp | Error): R;
1106
+ /**
1107
+ * Used to test that a function throws a error matching the most recent snapshot when it is called.
1108
+ */
1109
+ toThrowErrorMatchingSnapshot(snapshotName?: string): R;
1110
+ /**
1111
+ * Used to test that a function throws a error matching the most recent snapshot when it is called.
1112
+ * Instead of writing the snapshot value to a .snap file, it will be written into the source code automatically.
1113
+ */
1114
+ toThrowErrorMatchingInlineSnapshot(snapshot?: string): R;
1115
+ }
1116
+
1117
+ type RemoveFirstFromTuple<T extends any[]> = T['length'] extends 0
1118
+ ? []
1119
+ : ((...b: T) => void) extends (a: any, ...b: infer I) => void
1120
+ ? I
1121
+ : [];
1122
+
1123
+ interface AsymmetricMatcher {
1124
+ asymmetricMatch(other: unknown): boolean;
1125
+ }
1126
+ type NonAsyncMatchers<TMatchers extends ExpectExtendMap> = {
1127
+ [K in keyof TMatchers]: ReturnType<TMatchers[K]> extends Promise<CustomMatcherResult> ? never : K;
1128
+ }[keyof TMatchers];
1129
+ type CustomAsyncMatchers<TMatchers extends ExpectExtendMap> = {
1130
+ [K in NonAsyncMatchers<TMatchers>]: CustomAsymmetricMatcher<TMatchers[K]>;
1131
+ };
1132
+ type CustomAsymmetricMatcher<TMatcher extends (...args: any[]) => any> = (
1133
+ ...args: RemoveFirstFromTuple<Parameters<TMatcher>>
1134
+ ) => AsymmetricMatcher;
1135
+
1136
+ // should be TMatcherReturn extends void|Promise<void> but getting dtslint error
1137
+ type CustomJestMatcher<TMatcher extends (...args: any[]) => any, TMatcherReturn> = (
1138
+ ...args: RemoveFirstFromTuple<Parameters<TMatcher>>
1139
+ ) => TMatcherReturn;
1140
+
1141
+ type ExpectProperties = {
1142
+ [K in keyof Expect]: Expect[K];
1143
+ };
1144
+ // should be TMatcherReturn extends void|Promise<void> but getting dtslint error
1145
+ // Use the `void` type for return types only. Otherwise, use `undefined`. See: https://github.com/Microsoft/dtslint/blob/master/docs/void-return.md
1146
+ // have added issue https://github.com/microsoft/dtslint/issues/256 - Cannot have type union containing void ( to be used as return type only
1147
+ type ExtendedMatchers<TMatchers extends ExpectExtendMap, TMatcherReturn, TActual> = Matchers<
1148
+ TMatcherReturn,
1149
+ TActual
1150
+ > & { [K in keyof TMatchers]: CustomJestMatcher<TMatchers[K], TMatcherReturn> };
1151
+ type JestExtendedMatchers<TMatchers extends ExpectExtendMap, TActual> = JestMatchersShape<
1152
+ ExtendedMatchers<TMatchers, void, TActual>,
1153
+ ExtendedMatchers<TMatchers, Promise<void>, TActual>
1154
+ >;
1155
+
1156
+ // when have called expect.extend
1157
+ type ExtendedExpectFunction<TMatchers extends ExpectExtendMap> = <TActual>(
1158
+ actual: TActual,
1159
+ ) => JestExtendedMatchers<TMatchers, TActual>;
1160
+
1161
+ type ExtendedExpect<TMatchers extends ExpectExtendMap> = ExpectProperties &
1162
+ AndNot<CustomAsyncMatchers<TMatchers>> &
1163
+ ExtendedExpectFunction<TMatchers>;
1164
+
1165
+ type NonPromiseMatchers<T extends JestMatchersShape<any>> = Omit<T, 'resolves' | 'rejects' | 'not'>;
1166
+ type PromiseMatchers<T extends JestMatchersShape> = Omit<T['resolves'], 'not'>;
1167
+
1168
+ interface Constructable {
1169
+ new (...args: any[]): any;
1170
+ }
1171
+
1172
+ interface Mock<T = any, Y extends any[] = any> extends Function, MockInstance<T, Y> {
1173
+ new (...args: Y): T;
1174
+ (...args: Y): T;
1175
+ }
1176
+
1177
+ interface SpyInstance<T = any, Y extends any[] = any> extends MockInstance<T, Y> {}
1178
+
1179
+ /**
1180
+ * Constructs the type of a spied class.
1181
+ */
1182
+ type SpiedClass<T extends abstract new (...args: any) => any> = SpyInstance<
1183
+ InstanceType<T>,
1184
+ ConstructorParameters<T>
1185
+ >;
1186
+
1187
+ /**
1188
+ * Constructs the type of a spied function.
1189
+ */
1190
+ type SpiedFunction<T extends (...args: any) => any> = SpyInstance<ReturnType<T>, ArgsType<T>>;
1191
+
1192
+ /**
1193
+ * Constructs the type of a spied getter.
1194
+ */
1195
+ type SpiedGetter<T> = SpyInstance<T, []>;
1196
+
1197
+ /**
1198
+ * Constructs the type of a spied setter.
1199
+ */
1200
+ type SpiedSetter<T> = SpyInstance<void, [T]>;
1201
+
1202
+ /**
1203
+ * Constructs the type of a spied class or function.
1204
+ */
1205
+ type Spied<T extends (abstract new (...args: any) => any) | ((...args: any) => any)> = T extends abstract new (
1206
+ ...args: any
1207
+ ) => any
1208
+ ? SpiedClass<T>
1209
+ : T extends (...args: any) => any
1210
+ ? SpiedFunction<T>
1211
+ : never;
1212
+
1213
+ /**
1214
+ * Wrap a function with mock definitions
1215
+ *
1216
+ * @example
1217
+ *
1218
+ * import { myFunction } from "./library";
1219
+ * jest.mock("./library");
1220
+ *
1221
+ * const mockMyFunction = myFunction as jest.MockedFunction<typeof myFunction>;
1222
+ * expect(mockMyFunction.mock.calls[0][0]).toBe(42);
1223
+ */
1224
+ type MockedFunction<T extends (...args: any[]) => any> = MockInstance<ReturnType<T>, ArgsType<T>> & T;
1225
+
1226
+ /**
1227
+ * Wrap a class with mock definitions
1228
+ *
1229
+ * @example
1230
+ *
1231
+ * import { MyClass } from "./library";
1232
+ * jest.mock("./library");
1233
+ *
1234
+ * const mockedMyClass = MyClass as jest.MockedClass<typeof MyClass>;
1235
+ *
1236
+ * expect(mockedMyClass.mock.calls[0][0]).toBe(42); // Constructor calls
1237
+ * expect(mockedMyClass.prototype.myMethod.mock.calls[0][0]).toBe(42); // Method calls
1238
+ */
1239
+
1240
+ type MockedClass<T extends Constructable> = MockInstance<
1241
+ InstanceType<T>,
1242
+ T extends new (...args: infer P) => any ? P : never
1243
+ > & {
1244
+ prototype: T extends { prototype: any } ? Mocked<T['prototype']> : never;
1245
+ } & T;
1246
+
1247
+ /**
1248
+ * Wrap an object or a module with mock definitions
1249
+ *
1250
+ * @example
1251
+ *
1252
+ * jest.mock("../api");
1253
+ * import * as api from "../api";
1254
+ *
1255
+ * const mockApi = api as jest.Mocked<typeof api>;
1256
+ * api.MyApi.prototype.myApiMethod.mockImplementation(() => "test");
1257
+ */
1258
+ type Mocked<T> = {
1259
+ [P in keyof T]: T[P] extends (...args: any[]) => any
1260
+ ? MockInstance<ReturnType<T[P]>, ArgsType<T[P]>>
1261
+ : T[P] extends Constructable
1262
+ ? MockedClass<T[P]>
1263
+ : T[P];
1264
+ } & T;
1265
+
1266
+ interface MockInstance<T, Y extends any[]> {
1267
+ /** Returns the mock name string set by calling `mockFn.mockName(value)`. */
1268
+ getMockName(): string;
1269
+ /** Provides access to the mock's metadata */
1270
+ mock: MockContext<T, Y>;
1271
+ /**
1272
+ * Resets all information stored in the mockFn.mock.calls and mockFn.mock.instances arrays.
1273
+ *
1274
+ * Often this is useful when you want to clean up a mock's usage data between two assertions.
1275
+ *
1276
+ * Beware that `mockClear` will replace `mockFn.mock`, not just `mockFn.mock.calls` and `mockFn.mock.instances`.
1277
+ * You should therefore avoid assigning mockFn.mock to other variables, temporary or not, to make sure you
1278
+ * don't access stale data.
1279
+ */
1280
+ mockClear(): this;
1281
+ /**
1282
+ * Resets all information stored in the mock, including any initial implementation and mock name given.
1283
+ *
1284
+ * This is useful when you want to completely restore a mock back to its initial state.
1285
+ *
1286
+ * Beware that `mockReset` will replace `mockFn.mock`, not just `mockFn.mock.calls` and `mockFn.mock.instances`.
1287
+ * You should therefore avoid assigning mockFn.mock to other variables, temporary or not, to make sure you
1288
+ * don't access stale data.
1289
+ */
1290
+ mockReset(): this;
1291
+ /**
1292
+ * Does everything that `mockFn.mockReset()` does, and also restores the original (non-mocked) implementation.
1293
+ *
1294
+ * This is useful when you want to mock functions in certain test cases and restore the original implementation in others.
1295
+ *
1296
+ * Beware that `mockFn.mockRestore` only works when mock was created with `jest.spyOn`. Thus you have to take care of restoration
1297
+ * yourself when manually assigning `jest.fn()`.
1298
+ *
1299
+ * The [`restoreMocks`](https://jestjs.io/docs/en/configuration.html#restoremocks-boolean) configuration option is available
1300
+ * to restore mocks automatically between tests.
1301
+ */
1302
+ mockRestore(): void;
1303
+ /**
1304
+ * Returns the function that was set as the implementation of the mock (using mockImplementation).
1305
+ */
1306
+ getMockImplementation(): ((...args: Y) => T) | undefined;
1307
+ /**
1308
+ * Accepts a function that should be used as the implementation of the mock. The mock itself will still record
1309
+ * all calls that go into and instances that come from itself – the only difference is that the implementation
1310
+ * will also be executed when the mock is called.
1311
+ *
1312
+ * Note: `jest.fn(implementation)` is a shorthand for `jest.fn().mockImplementation(implementation)`.
1313
+ */
1314
+ mockImplementation(fn?: (...args: Y) => T): this;
1315
+ /**
1316
+ * Accepts a function that will be used as an implementation of the mock for one call to the mocked function.
1317
+ * Can be chained so that multiple function calls produce different results.
1318
+ *
1319
+ * @example
1320
+ *
1321
+ * const myMockFn = jest
1322
+ * .fn()
1323
+ * .mockImplementationOnce(cb => cb(null, true))
1324
+ * .mockImplementationOnce(cb => cb(null, false));
1325
+ *
1326
+ * myMockFn((err, val) => console.log(val)); // true
1327
+ *
1328
+ * myMockFn((err, val) => console.log(val)); // false
1329
+ */
1330
+ mockImplementationOnce(fn: (...args: Y) => T): this;
1331
+ /**
1332
+ * Temporarily overrides the default mock implementation within the callback,
1333
+ * then restores its previous implementation.
1334
+ *
1335
+ * @remarks
1336
+ * If the callback is async or returns a `thenable`, `withImplementation` will return a promise.
1337
+ * Awaiting the promise will await the callback and reset the implementation.
1338
+ */
1339
+ withImplementation(fn: (...args: Y) => T, callback: () => Promise<unknown>): Promise<void>;
1340
+ /**
1341
+ * Temporarily overrides the default mock implementation within the callback,
1342
+ * then restores its previous implementation.
1343
+ */
1344
+ withImplementation(fn: (...args: Y) => T, callback: () => void): void;
1345
+ /** Sets the name of the mock. */
1346
+ mockName(name: string): this;
1347
+ /**
1348
+ * Just a simple sugar function for:
1349
+ *
1350
+ * @example
1351
+ *
1352
+ * jest.fn(function() {
1353
+ * return this;
1354
+ * });
1355
+ */
1356
+ mockReturnThis(): this;
1357
+ /**
1358
+ * Accepts a value that will be returned whenever the mock function is called.
1359
+ *
1360
+ * @example
1361
+ *
1362
+ * const mock = jest.fn();
1363
+ * mock.mockReturnValue(42);
1364
+ * mock(); // 42
1365
+ * mock.mockReturnValue(43);
1366
+ * mock(); // 43
1367
+ */
1368
+ mockReturnValue(value: T): this;
1369
+ /**
1370
+ * Accepts a value that will be returned for one call to the mock function. Can be chained so that
1371
+ * successive calls to the mock function return different values. When there are no more
1372
+ * `mockReturnValueOnce` values to use, calls will return a value specified by `mockReturnValue`.
1373
+ *
1374
+ * @example
1375
+ *
1376
+ * const myMockFn = jest.fn()
1377
+ * .mockReturnValue('default')
1378
+ * .mockReturnValueOnce('first call')
1379
+ * .mockReturnValueOnce('second call');
1380
+ *
1381
+ * // 'first call', 'second call', 'default', 'default'
1382
+ * console.log(myMockFn(), myMockFn(), myMockFn(), myMockFn());
1383
+ *
1384
+ */
1385
+ mockReturnValueOnce(value: T): this;
1386
+ /**
1387
+ * Simple sugar function for: `jest.fn().mockImplementation(() => Promise.resolve(value));`
1388
+ */
1389
+ mockResolvedValue(value: ResolvedValue<T>): this;
1390
+ /**
1391
+ * Simple sugar function for: `jest.fn().mockImplementationOnce(() => Promise.resolve(value));`
1392
+ *
1393
+ * @example
1394
+ *
1395
+ * test('async test', async () => {
1396
+ * const asyncMock = jest
1397
+ * .fn()
1398
+ * .mockResolvedValue('default')
1399
+ * .mockResolvedValueOnce('first call')
1400
+ * .mockResolvedValueOnce('second call');
1401
+ *
1402
+ * await asyncMock(); // first call
1403
+ * await asyncMock(); // second call
1404
+ * await asyncMock(); // default
1405
+ * await asyncMock(); // default
1406
+ * });
1407
+ *
1408
+ */
1409
+ mockResolvedValueOnce(value: ResolvedValue<T>): this;
1410
+ /**
1411
+ * Simple sugar function for: `jest.fn().mockImplementation(() => Promise.reject(value));`
1412
+ *
1413
+ * @example
1414
+ *
1415
+ * test('async test', async () => {
1416
+ * const asyncMock = jest.fn().mockRejectedValue(new Error('Async error'));
1417
+ *
1418
+ * await asyncMock(); // throws "Async error"
1419
+ * });
1420
+ */
1421
+ mockRejectedValue(value: RejectedValue<T>): this;
1422
+
1423
+ /**
1424
+ * Simple sugar function for: `jest.fn().mockImplementationOnce(() => Promise.reject(value));`
1425
+ *
1426
+ * @example
1427
+ *
1428
+ * test('async test', async () => {
1429
+ * const asyncMock = jest
1430
+ * .fn()
1431
+ * .mockResolvedValueOnce('first call')
1432
+ * .mockRejectedValueOnce(new Error('Async error'));
1433
+ *
1434
+ * await asyncMock(); // first call
1435
+ * await asyncMock(); // throws "Async error"
1436
+ * });
1437
+ *
1438
+ */
1439
+ mockRejectedValueOnce(value: RejectedValue<T>): this;
1440
+ }
1441
+
1442
+ /**
1443
+ * Represents the result of a single call to a mock function with a return value.
1444
+ */
1445
+ interface MockResultReturn<T> {
1446
+ type: 'return';
1447
+ value: T;
1448
+ }
1449
+ /**
1450
+ * Represents the result of a single incomplete call to a mock function.
1451
+ */
1452
+ interface MockResultIncomplete {
1453
+ type: 'incomplete';
1454
+ value: undefined;
1455
+ }
1456
+ /**
1457
+ * Represents the result of a single call to a mock function with a thrown error.
1458
+ */
1459
+ interface MockResultThrow {
1460
+ type: 'throw';
1461
+ value: any;
1462
+ }
1463
+
1464
+ type MockResult<T> = MockResultReturn<T> | MockResultThrow | MockResultIncomplete;
1465
+
1466
+ interface MockContext<T, Y extends any[]> {
1467
+ /**
1468
+ * List of the call arguments of all calls that have been made to the mock.
1469
+ */
1470
+ calls: Y[];
1471
+ /**
1472
+ * List of all the object instances that have been instantiated from the mock.
1473
+ */
1474
+ instances: T[];
1475
+ /**
1476
+ * List of the call order indexes of the mock. Jest is indexing the order of
1477
+ * invocations of all mocks in a test file. The index is starting with `1`.
1478
+ */
1479
+ invocationCallOrder: number[];
1480
+ /**
1481
+ * List of the call arguments of the last call that was made to the mock.
1482
+ * If the function was not called, it will return `undefined`.
1483
+ */
1484
+ lastCall?: Y;
1485
+ /**
1486
+ * List of the results of all calls that have been made to the mock.
1487
+ */
1488
+ results: Array<MockResult<T>>;
1489
+ }
1490
+ }
1491
+
1492
+ // Jest ships with a copy of Jasmine. They monkey-patch its APIs and divergence/deprecation are expected.
1493
+ // Relevant parts of Jasmine's API are below so they can be changed and removed over time.
1494
+ // This file can't reference jasmine.d.ts since the globals aren't compatible.
1495
+
1496
+ declare function spyOn<T>(object: T, method: keyof T): jasmine.Spy;
1497
+ /**
1498
+ * If you call the function pending anywhere in the spec body,
1499
+ * no matter the expectations, the spec will be marked pending.
1500
+ */
1501
+ declare function pending(reason?: string): void;
1502
+ /**
1503
+ * Fails a test when called within one.
1504
+ */
1505
+ declare function fail(error?: any): never;
1506
+ declare namespace jasmine {
1507
+ let DEFAULT_TIMEOUT_INTERVAL: number;
1508
+ function clock(): Clock;
1509
+ function any(aclass: any): Any;
1510
+ function anything(): Any;
1511
+ function arrayContaining(sample: any[]): ArrayContaining;
1512
+ function objectContaining(sample: any): ObjectContaining;
1513
+ function createSpy(name?: string, originalFn?: (...args: any[]) => any): Spy;
1514
+ function createSpyObj(baseName: string, methodNames: any[]): any;
1515
+ // tslint:disable-next-line: no-unnecessary-generics
1516
+ function createSpyObj<T>(baseName: string, methodNames: any[]): T;
1517
+ function pp(value: any): string;
1518
+ function addCustomEqualityTester(equalityTester: CustomEqualityTester): void;
1519
+ function stringMatching(value: string | RegExp): Any;
1520
+
1521
+ interface Clock {
1522
+ install(): void;
1523
+ uninstall(): void;
1524
+ /**
1525
+ * Calls to any registered callback are triggered when the clock isticked forward
1526
+ * via the jasmine.clock().tick function, which takes a number of milliseconds.
1527
+ */
1528
+ tick(ms: number): void;
1529
+ mockDate(date?: Date): void;
1530
+ }
1531
+
1532
+ interface Any {
1533
+ new (expectedClass: any): any;
1534
+ jasmineMatches(other: any): boolean;
1535
+ jasmineToString(): string;
1536
+ }
1537
+
1538
+ interface ArrayContaining {
1539
+ new (sample: any[]): any;
1540
+ asymmetricMatch(other: any): boolean;
1541
+ jasmineToString(): string;
1542
+ }
1543
+
1544
+ interface ObjectContaining {
1545
+ new (sample: any): any;
1546
+ jasmineMatches(other: any, mismatchKeys: any[], mismatchValues: any[]): boolean;
1547
+ jasmineToString(): string;
1548
+ }
1549
+
1550
+ interface Spy {
1551
+ (...params: any[]): any;
1552
+ identity: string;
1553
+ and: SpyAnd;
1554
+ calls: Calls;
1555
+ mostRecentCall: { args: any[] };
1556
+ argsForCall: any[];
1557
+ wasCalled: boolean;
1558
+ }
1559
+
1560
+ interface SpyAnd {
1561
+ /**
1562
+ * By chaining the spy with and.callThrough, the spy will still track all
1563
+ * calls to it but in addition it will delegate to the actual implementation.
1564
+ */
1565
+ callThrough(): Spy;
1566
+ /**
1567
+ * By chaining the spy with and.returnValue, all calls to the function
1568
+ * will return a specific value.
1569
+ */
1570
+ returnValue(val: any): Spy;
1571
+ /**
1572
+ * By chaining the spy with and.returnValues, all calls to the function
1573
+ * will return specific values in order until it reaches the end of the return values list.
1574
+ */
1575
+ returnValues(...values: any[]): Spy;
1576
+ /**
1577
+ * By chaining the spy with and.callFake, all calls to the spy
1578
+ * will delegate to the supplied function.
1579
+ */
1580
+ callFake(fn: (...args: any[]) => any): Spy;
1581
+ /**
1582
+ * By chaining the spy with and.throwError, all calls to the spy
1583
+ * will throw the specified value.
1584
+ */
1585
+ throwError(msg: string): Spy;
1586
+ /**
1587
+ * When a calling strategy is used for a spy, the original stubbing
1588
+ * behavior can be returned at any time with and.stub.
1589
+ */
1590
+ stub(): Spy;
1591
+ }
1592
+
1593
+ interface Calls {
1594
+ /**
1595
+ * By chaining the spy with calls.any(),
1596
+ * will return false if the spy has not been called at all,
1597
+ * and then true once at least one call happens.
1598
+ */
1599
+ any(): boolean;
1600
+ /**
1601
+ * By chaining the spy with calls.count(),
1602
+ * will return the number of times the spy was called
1603
+ */
1604
+ count(): number;
1605
+ /**
1606
+ * By chaining the spy with calls.argsFor(),
1607
+ * will return the arguments passed to call number index
1608
+ */
1609
+ argsFor(index: number): any[];
1610
+ /**
1611
+ * By chaining the spy with calls.allArgs(),
1612
+ * will return the arguments to all calls
1613
+ */
1614
+ allArgs(): any[];
1615
+ /**
1616
+ * By chaining the spy with calls.all(), will return the
1617
+ * context (the this) and arguments passed all calls
1618
+ */
1619
+ all(): CallInfo[];
1620
+ /**
1621
+ * By chaining the spy with calls.mostRecent(), will return the
1622
+ * context (the this) and arguments for the most recent call
1623
+ */
1624
+ mostRecent(): CallInfo;
1625
+ /**
1626
+ * By chaining the spy with calls.first(), will return the
1627
+ * context (the this) and arguments for the first call
1628
+ */
1629
+ first(): CallInfo;
1630
+ /**
1631
+ * By chaining the spy with calls.reset(), will clears all tracking for a spy
1632
+ */
1633
+ reset(): void;
1634
+ }
1635
+
1636
+ interface CallInfo {
1637
+ /**
1638
+ * The context (the this) for the call
1639
+ */
1640
+ object: any;
1641
+ /**
1642
+ * All arguments passed to the call
1643
+ */
1644
+ args: any[];
1645
+ /**
1646
+ * The return value of the call
1647
+ */
1648
+ returnValue: any;
1649
+ }
1650
+
1651
+ interface CustomMatcherFactories {
1652
+ [index: string]: CustomMatcherFactory;
1653
+ }
1654
+
1655
+ type CustomMatcherFactory = (util: MatchersUtil, customEqualityTesters: CustomEqualityTester[]) => CustomMatcher;
1656
+
1657
+ interface MatchersUtil {
1658
+ equals(a: any, b: any, customTesters?: CustomEqualityTester[]): boolean;
1659
+ // tslint:disable-next-line: no-unnecessary-generics
1660
+ contains<T>(haystack: ArrayLike<T> | string, needle: any, customTesters?: CustomEqualityTester[]): boolean;
1661
+ buildFailureMessage(matcherName: string, isNot: boolean, actual: any, ...expected: any[]): string;
1662
+ }
1663
+
1664
+ type CustomEqualityTester = (first: any, second: any) => boolean;
1665
+
1666
+ interface CustomMatcher {
1667
+ compare<T>(actual: T, expected: T, ...args: any[]): CustomMatcherResult;
1668
+ compare(actual: any, ...expected: any[]): CustomMatcherResult;
1669
+ }
1670
+
1671
+ interface CustomMatcherResult {
1672
+ pass: boolean;
1673
+ message: string | (() => string);
1674
+ }
1675
+
1676
+ interface ArrayLike<T> {
1677
+ length: number;
1678
+ [n: number]: T;
1679
+ }
1680
+ }
1681
+
1682
+ interface ImportMeta {
1683
+ jest: typeof jest;
1684
+ }