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