expect-webdriverio 1.2.0 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -455
- package/lib/jasmineUtils.js +205 -0
- package/lib/matchers/element/toHaveChildren.js +9 -2
- package/lib/matchers/element/{toHaveClass.js → toHaveElementClass.js} +8 -3
- package/lib/matchers/element/toHaveElementClassContaining.js +20 -0
- package/lib/matchers/element/{toHaveProperty.js → toHaveElementProperty.js} +9 -4
- package/lib/matchers/element/toHaveValue.js +2 -2
- package/lib/matchers/mock/toBeRequested.js +12 -0
- package/lib/matchers/mock/toBeRequestedTimes.js +37 -0
- package/lib/matchers/mock/toBeRequestedWith.js +215 -0
- package/lib/matchers/mock/toBeRequestedWithResponse.js +13 -0
- package/lib/matchers.js +7 -3
- package/lib/options.js +2 -1
- package/lib/util/formatMessage.js +2 -1
- package/lib/utils.js +2 -1
- package/package.json +27 -17
- package/types/expect-webdriverio.d.ts +174 -85
- package/types/jest-global.d.ts +2 -2
- package/types/standalone-global.d.ts +2 -2
- package/types/standalone.d.ts +24 -2
- package/lib/matchers/element/toHaveClassContaining.js +0 -15
- package/lib/types/some-expect.js +0 -0
- package/types/jest-expect-clone/jest-expect.d.ts +0 -502
|
@@ -1,502 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Copied this one from `@jest/types`
|
|
5
|
-
* Need to think how to deal with it better.
|
|
6
|
-
* Sorry to say I can't import `expect` from `@jest/types`
|
|
7
|
-
* as a result `@jest/types` conflicts with other test runners like `mocha`.
|
|
8
|
-
*
|
|
9
|
-
* https://github.com/facebook/jest/issues/9209
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
type EqualityTester = (a: any, b: any) => boolean | undefined;
|
|
13
|
-
type MatcherContext = jest.MatcherUtils & Readonly<jest.MatcherState>;
|
|
14
|
-
type CustomMatcher = (
|
|
15
|
-
this: MatcherContext,
|
|
16
|
-
received: any,
|
|
17
|
-
...actual: any[]
|
|
18
|
-
) => jest.CustomMatcherResult | Promise<jest.CustomMatcherResult>;
|
|
19
|
-
|
|
20
|
-
type JestMatchers<T> = JestMatchersShape<jest.Matchers<void, T>, jest.Matchers<Promise<void>, T>>;
|
|
21
|
-
|
|
22
|
-
type JestMatchersShape<TNonPromise extends {} = {}, TPromise extends {} = {}> = {
|
|
23
|
-
/**
|
|
24
|
-
* Use resolves to unwrap the value of a fulfilled promise so any other
|
|
25
|
-
* matcher can be chained. If the promise is rejected the assertion fails.
|
|
26
|
-
*/
|
|
27
|
-
resolves: AndNot<TPromise>;
|
|
28
|
-
/**
|
|
29
|
-
* Unwraps the reason of a rejected promise so any other matcher can be chained.
|
|
30
|
-
* If the promise is fulfilled the assertion fails.
|
|
31
|
-
*/
|
|
32
|
-
rejects: AndNot<TPromise>;
|
|
33
|
-
} & AndNot<TNonPromise>;
|
|
34
|
-
type AndNot<T> = T & {
|
|
35
|
-
not: T;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
declare namespace jest {
|
|
39
|
-
interface Constructable {
|
|
40
|
-
new(...args: any[]): any;
|
|
41
|
-
}
|
|
42
|
-
interface ExpectExtendMap {
|
|
43
|
-
[key: string]: CustomMatcher;
|
|
44
|
-
}
|
|
45
|
-
interface CustomMatcherResult {
|
|
46
|
-
pass: boolean;
|
|
47
|
-
message: () => string;
|
|
48
|
-
}
|
|
49
|
-
interface MatcherState {
|
|
50
|
-
assertionCalls: number;
|
|
51
|
-
currentTestName: string;
|
|
52
|
-
expand: boolean;
|
|
53
|
-
expectedAssertionsNumber: number;
|
|
54
|
-
isExpectingAssertions?: boolean;
|
|
55
|
-
suppressedErrors: Error[];
|
|
56
|
-
testPath: string;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
interface MatcherUtils {
|
|
60
|
-
readonly isNot: boolean;
|
|
61
|
-
readonly dontThrow: () => void;
|
|
62
|
-
readonly promise: string;
|
|
63
|
-
readonly assertionCalls: number;
|
|
64
|
-
readonly expectedAssertionsNumber: number | null;
|
|
65
|
-
readonly isExpectingAssertions: boolean;
|
|
66
|
-
readonly suppressedErrors: any[];
|
|
67
|
-
readonly expand: boolean;
|
|
68
|
-
readonly testPath: string;
|
|
69
|
-
readonly currentTestName: string;
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* This is a deep-equality function that will return true if two objects have the same values (recursively).
|
|
73
|
-
*/
|
|
74
|
-
equals(a: any, b: any, customTesters?: EqualityTester[], strictCheck?: boolean): boolean;
|
|
75
|
-
[other: string]: any;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
interface Matchers<R, T> {
|
|
79
|
-
/**
|
|
80
|
-
* Ensures the last call to a mock function was provided specific args.
|
|
81
|
-
*
|
|
82
|
-
* Optionally, you can provide a type for the expected arguments via a generic.
|
|
83
|
-
* Note that the type must be either an array or a tuple.
|
|
84
|
-
*/
|
|
85
|
-
lastCalledWith<E extends any[]>(...args: E): R;
|
|
86
|
-
/**
|
|
87
|
-
* Ensure that the last call to a mock function has returned a specified value.
|
|
88
|
-
*
|
|
89
|
-
* Optionally, you can provide a type for the expected value via a generic.
|
|
90
|
-
* This is particularly useful for ensuring expected objects have the right structure.
|
|
91
|
-
*/
|
|
92
|
-
lastReturnedWith<E = any>(value: E): R;
|
|
93
|
-
/**
|
|
94
|
-
* Ensure that a mock function is called with specific arguments on an Nth call.
|
|
95
|
-
*
|
|
96
|
-
* Optionally, you can provide a type for the expected arguments via a generic.
|
|
97
|
-
* Note that the type must be either an array or a tuple.
|
|
98
|
-
*/
|
|
99
|
-
nthCalledWith<E extends any[]>(nthCall: number, ...params: E): R;
|
|
100
|
-
/**
|
|
101
|
-
* Ensure that the nth call to a mock function has returned a specified value.
|
|
102
|
-
*
|
|
103
|
-
* Optionally, you can provide a type for the expected value via a generic.
|
|
104
|
-
* This is particularly useful for ensuring expected objects have the right structure.
|
|
105
|
-
*/
|
|
106
|
-
nthReturnedWith<E = any>(n: number, value: E): R;
|
|
107
|
-
/**
|
|
108
|
-
* Checks that a value is what you expect. It uses `===` to check strict equality.
|
|
109
|
-
* Don't use `toBe` with floating-point numbers.
|
|
110
|
-
*
|
|
111
|
-
* Optionally, you can provide a type for the expected value via a generic.
|
|
112
|
-
* This is particularly useful for ensuring expected objects have the right structure.
|
|
113
|
-
*/
|
|
114
|
-
toBe<E = any>(expected: E): R;
|
|
115
|
-
/**
|
|
116
|
-
* Ensures that a mock function is called.
|
|
117
|
-
*/
|
|
118
|
-
toBeCalled(): R;
|
|
119
|
-
/**
|
|
120
|
-
* Ensures that a mock function is called an exact number of times.
|
|
121
|
-
*/
|
|
122
|
-
toBeCalledTimes(expected: number): R;
|
|
123
|
-
/**
|
|
124
|
-
* Ensure that a mock function is called with specific arguments.
|
|
125
|
-
*
|
|
126
|
-
* Optionally, you can provide a type for the expected arguments via a generic.
|
|
127
|
-
* Note that the type must be either an array or a tuple.
|
|
128
|
-
*/
|
|
129
|
-
toBeCalledWith<E extends any[]>(...args: E): R;
|
|
130
|
-
/**
|
|
131
|
-
* Using exact equality with floating point numbers is a bad idea.
|
|
132
|
-
* Rounding means that intuitive things fail.
|
|
133
|
-
* The default for numDigits is 2.
|
|
134
|
-
*/
|
|
135
|
-
toBeCloseTo(expected: number, numDigits?: number): R;
|
|
136
|
-
/**
|
|
137
|
-
* Ensure that a variable is not undefined.
|
|
138
|
-
*/
|
|
139
|
-
toBeDefined(): R;
|
|
140
|
-
/**
|
|
141
|
-
* When you don't care what a value is, you just want to
|
|
142
|
-
* ensure a value is false in a boolean context.
|
|
143
|
-
*/
|
|
144
|
-
toBeFalsy(): R;
|
|
145
|
-
/**
|
|
146
|
-
* For comparing floating point numbers.
|
|
147
|
-
*/
|
|
148
|
-
toBeGreaterThan(expected: number): R;
|
|
149
|
-
/**
|
|
150
|
-
* For comparing floating point numbers.
|
|
151
|
-
*/
|
|
152
|
-
toBeGreaterThanOrEqual(expected: number): R;
|
|
153
|
-
/**
|
|
154
|
-
* Ensure that an object is an instance of a class.
|
|
155
|
-
* This matcher uses `instanceof` underneath.
|
|
156
|
-
*
|
|
157
|
-
* Optionally, you can provide a type for the expected value via a generic.
|
|
158
|
-
* This is particularly useful for ensuring expected objects have the right structure.
|
|
159
|
-
*/
|
|
160
|
-
toBeInstanceOf<E = any>(expected: E): R;
|
|
161
|
-
/**
|
|
162
|
-
* For comparing floating point numbers.
|
|
163
|
-
*/
|
|
164
|
-
toBeLessThan(expected: number): R;
|
|
165
|
-
/**
|
|
166
|
-
* For comparing floating point numbers.
|
|
167
|
-
*/
|
|
168
|
-
toBeLessThanOrEqual(expected: number): R;
|
|
169
|
-
/**
|
|
170
|
-
* This is the same as `.toBe(null)` but the error messages are a bit nicer.
|
|
171
|
-
* So use `.toBeNull()` when you want to check that something is null.
|
|
172
|
-
*/
|
|
173
|
-
toBeNull(): R;
|
|
174
|
-
/**
|
|
175
|
-
* Use when you don't care what a value is, you just want to ensure a value
|
|
176
|
-
* is true in a boolean context. In JavaScript, there are six falsy values:
|
|
177
|
-
* `false`, `0`, `''`, `null`, `undefined`, and `NaN`. Everything else is truthy.
|
|
178
|
-
*/
|
|
179
|
-
toBeTruthy(): R;
|
|
180
|
-
/**
|
|
181
|
-
* Used to check that a variable is undefined.
|
|
182
|
-
*/
|
|
183
|
-
toBeUndefined(): R;
|
|
184
|
-
/**
|
|
185
|
-
* Used to check that a variable is NaN.
|
|
186
|
-
*/
|
|
187
|
-
toBeNaN(): R;
|
|
188
|
-
/**
|
|
189
|
-
* Used when you want to check that an item is in a list.
|
|
190
|
-
* For testing the items in the list, this uses `===`, a strict equality check.
|
|
191
|
-
*
|
|
192
|
-
* Optionally, you can provide a type for the expected value via a generic.
|
|
193
|
-
* This is particularly useful for ensuring expected objects have the right structure.
|
|
194
|
-
*/
|
|
195
|
-
toContain<E = any>(expected: E): R;
|
|
196
|
-
/**
|
|
197
|
-
* Used when you want to check that an item is in a list.
|
|
198
|
-
* For testing the items in the list, this matcher recursively checks the
|
|
199
|
-
* equality of all fields, rather than checking for object identity.
|
|
200
|
-
*
|
|
201
|
-
* Optionally, you can provide a type for the expected value via a generic.
|
|
202
|
-
* This is particularly useful for ensuring expected objects have the right structure.
|
|
203
|
-
*/
|
|
204
|
-
toContainEqual<E = any>(expected: E): R;
|
|
205
|
-
/**
|
|
206
|
-
* Used when you want to check that two objects have the same value.
|
|
207
|
-
* This matcher recursively checks the equality of all fields, rather than checking for object identity.
|
|
208
|
-
*
|
|
209
|
-
* Optionally, you can provide a type for the expected value via a generic.
|
|
210
|
-
* This is particularly useful for ensuring expected objects have the right structure.
|
|
211
|
-
*/
|
|
212
|
-
toEqual<E = any>(expected: E): R;
|
|
213
|
-
/**
|
|
214
|
-
* Ensures that a mock function is called.
|
|
215
|
-
*/
|
|
216
|
-
toHaveBeenCalled(): R;
|
|
217
|
-
/**
|
|
218
|
-
* Ensures that a mock function is called an exact number of times.
|
|
219
|
-
*/
|
|
220
|
-
toHaveBeenCalledTimes(expected: number): R;
|
|
221
|
-
/**
|
|
222
|
-
* Ensure that a mock function is called with specific arguments.
|
|
223
|
-
*
|
|
224
|
-
* Optionally, you can provide a type for the expected arguments via a generic.
|
|
225
|
-
* Note that the type must be either an array or a tuple.
|
|
226
|
-
*/
|
|
227
|
-
toHaveBeenCalledWith<E extends any[]>(...params: E): R;
|
|
228
|
-
/**
|
|
229
|
-
* Ensure that a mock function is called with specific arguments on an Nth call.
|
|
230
|
-
*
|
|
231
|
-
* Optionally, you can provide a type for the expected arguments via a generic.
|
|
232
|
-
* Note that the type must be either an array or a tuple.
|
|
233
|
-
*/
|
|
234
|
-
toHaveBeenNthCalledWith<E extends any[]>(nthCall: number, ...params: E): R;
|
|
235
|
-
/**
|
|
236
|
-
* If you have a mock function, you can use `.toHaveBeenLastCalledWith`
|
|
237
|
-
* to test what arguments it was last called with.
|
|
238
|
-
*
|
|
239
|
-
* Optionally, you can provide a type for the expected arguments via a generic.
|
|
240
|
-
* Note that the type must be either an array or a tuple.
|
|
241
|
-
*/
|
|
242
|
-
toHaveBeenLastCalledWith<E extends any[]>(...params: E): R;
|
|
243
|
-
/**
|
|
244
|
-
* Use to test the specific value that a mock function last returned.
|
|
245
|
-
* If the last call to the mock function threw an error, then this matcher will fail
|
|
246
|
-
* no matter what value you provided as the expected return value.
|
|
247
|
-
*
|
|
248
|
-
* Optionally, you can provide a type for the expected value via a generic.
|
|
249
|
-
* This is particularly useful for ensuring expected objects have the right structure.
|
|
250
|
-
*/
|
|
251
|
-
toHaveLastReturnedWith<E = any>(expected: E): R;
|
|
252
|
-
/**
|
|
253
|
-
* Used to check that an object has a `.length` property
|
|
254
|
-
* and it is set to a certain numeric value.
|
|
255
|
-
*/
|
|
256
|
-
toHaveLength(expected: number): R;
|
|
257
|
-
/**
|
|
258
|
-
* Use to test the specific value that a mock function returned for the nth call.
|
|
259
|
-
* If the nth call to the mock function threw an error, then this matcher will fail
|
|
260
|
-
* no matter what value you provided as the expected return value.
|
|
261
|
-
*
|
|
262
|
-
* Optionally, you can provide a type for the expected value via a generic.
|
|
263
|
-
* This is particularly useful for ensuring expected objects have the right structure.
|
|
264
|
-
*/
|
|
265
|
-
toHaveNthReturnedWith<E = any>(nthCall: number, expected: E): R;
|
|
266
|
-
/**
|
|
267
|
-
* Use to check if property at provided reference keyPath exists for an object.
|
|
268
|
-
* For checking deeply nested properties in an object you may use dot notation or an array containing
|
|
269
|
-
* the keyPath for deep references.
|
|
270
|
-
*
|
|
271
|
-
* Optionally, you can provide a value to check if it's equal to the value present at keyPath
|
|
272
|
-
* on the target object. This matcher uses 'deep equality' (like `toEqual()`) and recursively checks
|
|
273
|
-
* the equality of all fields.
|
|
274
|
-
*
|
|
275
|
-
* @example
|
|
276
|
-
*
|
|
277
|
-
* expect(houseForSale).toHaveProperty('kitchen.area', 20);
|
|
278
|
-
*/
|
|
279
|
-
toHaveProperty<E = any>(propertyPath: string | any[], value?: E): R;
|
|
280
|
-
/**
|
|
281
|
-
* Use to test that the mock function successfully returned (i.e., did not throw an error) at least one time
|
|
282
|
-
*/
|
|
283
|
-
toHaveReturned(): R;
|
|
284
|
-
/**
|
|
285
|
-
* Use to ensure that a mock function returned successfully (i.e., did not throw an error) an exact number of times.
|
|
286
|
-
* Any calls to the mock function that throw an error are not counted toward the number of times the function returned.
|
|
287
|
-
*/
|
|
288
|
-
toHaveReturnedTimes(expected: number): R;
|
|
289
|
-
/**
|
|
290
|
-
* Use to ensure that a mock function returned a specific value.
|
|
291
|
-
*
|
|
292
|
-
* Optionally, you can provide a type for the expected value via a generic.
|
|
293
|
-
* This is particularly useful for ensuring expected objects have the right structure.
|
|
294
|
-
*/
|
|
295
|
-
toHaveReturnedWith<E = any>(expected: E): R;
|
|
296
|
-
/**
|
|
297
|
-
* Check that a string matches a regular expression.
|
|
298
|
-
*/
|
|
299
|
-
toMatch(expected: string | RegExp): R;
|
|
300
|
-
/**
|
|
301
|
-
* Used to check that a JavaScript object matches a subset of the properties of an object
|
|
302
|
-
*
|
|
303
|
-
* Optionally, you can provide an object to use as Generic type for the expected value.
|
|
304
|
-
* This ensures that the matching object matches the structure of the provided object-like type.
|
|
305
|
-
*
|
|
306
|
-
* @example
|
|
307
|
-
*
|
|
308
|
-
* type House = {
|
|
309
|
-
* bath: boolean;
|
|
310
|
-
* bedrooms: number;
|
|
311
|
-
* kitchen: {
|
|
312
|
-
* amenities: string[];
|
|
313
|
-
* area: number;
|
|
314
|
-
* wallColor: string;
|
|
315
|
-
* }
|
|
316
|
-
* };
|
|
317
|
-
*
|
|
318
|
-
* expect(desiredHouse).toMatchObject<House>(...standardHouse, kitchen: {area: 20}) // wherein standardHouse is some base object of type House
|
|
319
|
-
*/
|
|
320
|
-
toMatchObject<E extends {} | any[]>(expected: E): R;
|
|
321
|
-
/**
|
|
322
|
-
* This ensures that a value matches the most recent snapshot with property matchers.
|
|
323
|
-
* Check out [the Snapshot Testing guide](http://facebook.github.io/jest/docs/snapshot-testing.html) for more information.
|
|
324
|
-
*/
|
|
325
|
-
toMatchSnapshot<U extends { [P in keyof T]: any }>(propertyMatchers: Partial<U>, snapshotName?: string): R;
|
|
326
|
-
/**
|
|
327
|
-
* This ensures that a value matches the most recent snapshot.
|
|
328
|
-
* Check out [the Snapshot Testing guide](http://facebook.github.io/jest/docs/snapshot-testing.html) for more information.
|
|
329
|
-
*/
|
|
330
|
-
toMatchSnapshot(snapshotName?: string): R;
|
|
331
|
-
/**
|
|
332
|
-
* This ensures that a value matches the most recent snapshot with property matchers.
|
|
333
|
-
* Instead of writing the snapshot value to a .snap file, it will be written into the source code automatically.
|
|
334
|
-
* Check out [the Snapshot Testing guide](http://facebook.github.io/jest/docs/snapshot-testing.html) for more information.
|
|
335
|
-
*/
|
|
336
|
-
toMatchInlineSnapshot<U extends { [P in keyof T]: any }>(propertyMatchers: Partial<U>, snapshot?: string): R;
|
|
337
|
-
/**
|
|
338
|
-
* This ensures that a value matches the most recent snapshot with property matchers.
|
|
339
|
-
* Instead of writing the snapshot value to a .snap file, it will be written into the source code automatically.
|
|
340
|
-
* Check out [the Snapshot Testing guide](http://facebook.github.io/jest/docs/snapshot-testing.html) for more information.
|
|
341
|
-
*/
|
|
342
|
-
toMatchInlineSnapshot(snapshot?: string): R;
|
|
343
|
-
/**
|
|
344
|
-
* Ensure that a mock function has returned (as opposed to thrown) at least once.
|
|
345
|
-
*/
|
|
346
|
-
toReturn(): R;
|
|
347
|
-
/**
|
|
348
|
-
* Ensure that a mock function has returned (as opposed to thrown) a specified number of times.
|
|
349
|
-
*/
|
|
350
|
-
toReturnTimes(count: number): R;
|
|
351
|
-
/**
|
|
352
|
-
* Ensure that a mock function has returned a specified value at least once.
|
|
353
|
-
*
|
|
354
|
-
* Optionally, you can provide a type for the expected value via a generic.
|
|
355
|
-
* This is particularly useful for ensuring expected objects have the right structure.
|
|
356
|
-
*/
|
|
357
|
-
toReturnWith<E = any>(value: E): R;
|
|
358
|
-
/**
|
|
359
|
-
* Use to test that objects have the same types as well as structure.
|
|
360
|
-
*
|
|
361
|
-
* Optionally, you can provide a type for the expected value via a generic.
|
|
362
|
-
* This is particularly useful for ensuring expected objects have the right structure.
|
|
363
|
-
*/
|
|
364
|
-
toStrictEqual<E = any>(expected: E): R;
|
|
365
|
-
/**
|
|
366
|
-
* Used to test that a function throws when it is called.
|
|
367
|
-
*/
|
|
368
|
-
toThrow(error?: string | Constructable | RegExp | Error): R;
|
|
369
|
-
/**
|
|
370
|
-
* If you want to test that a specific error is thrown inside a function.
|
|
371
|
-
*/
|
|
372
|
-
toThrowError(error?: string | Constructable | RegExp | Error): R;
|
|
373
|
-
/**
|
|
374
|
-
* Used to test that a function throws a error matching the most recent snapshot when it is called.
|
|
375
|
-
*/
|
|
376
|
-
toThrowErrorMatchingSnapshot(): R;
|
|
377
|
-
/**
|
|
378
|
-
* Used to test that a function throws a error matching the most recent snapshot when it is called.
|
|
379
|
-
* Instead of writing the snapshot value to a .snap file, it will be written into the source code automatically.
|
|
380
|
-
*/
|
|
381
|
-
toThrowErrorMatchingInlineSnapshot(snapshot?: string): R;
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
interface Expect {
|
|
385
|
-
/**
|
|
386
|
-
* The `expect` function is used every time you want to test a value.
|
|
387
|
-
* You will rarely call `expect` by itself.
|
|
388
|
-
*
|
|
389
|
-
* @param actual The value to apply matchers against.
|
|
390
|
-
*/
|
|
391
|
-
<T = any>(actual: T): JestMatchers<T>;
|
|
392
|
-
/**
|
|
393
|
-
* Matches anything but null or undefined. You can use it inside `toEqual` or `toBeCalledWith` instead
|
|
394
|
-
* of a literal value. For example, if you want to check that a mock function is called with a
|
|
395
|
-
* non-null argument:
|
|
396
|
-
*
|
|
397
|
-
* @example
|
|
398
|
-
*
|
|
399
|
-
* test('map calls its argument with a non-null argument', () => {
|
|
400
|
-
* const mock = jest.fn();
|
|
401
|
-
* [1].map(x => mock(x));
|
|
402
|
-
* expect(mock).toBeCalledWith(expect.anything());
|
|
403
|
-
* });
|
|
404
|
-
*
|
|
405
|
-
*/
|
|
406
|
-
anything(): any;
|
|
407
|
-
/**
|
|
408
|
-
* Matches anything that was created with the given constructor.
|
|
409
|
-
* You can use it inside `toEqual` or `toBeCalledWith` instead of a literal value.
|
|
410
|
-
*
|
|
411
|
-
* @example
|
|
412
|
-
*
|
|
413
|
-
* function randocall(fn) {
|
|
414
|
-
* return fn(Math.floor(Math.random() * 6 + 1));
|
|
415
|
-
* }
|
|
416
|
-
*
|
|
417
|
-
* test('randocall calls its callback with a number', () => {
|
|
418
|
-
* const mock = jest.fn();
|
|
419
|
-
* randocall(mock);
|
|
420
|
-
* expect(mock).toBeCalledWith(expect.any(Number));
|
|
421
|
-
* });
|
|
422
|
-
*/
|
|
423
|
-
any(classType: any): any;
|
|
424
|
-
/**
|
|
425
|
-
* Matches any array made up entirely of elements in the provided array.
|
|
426
|
-
* You can use it inside `toEqual` or `toBeCalledWith` instead of a literal value.
|
|
427
|
-
*
|
|
428
|
-
* Optionally, you can provide a type for the elements via a generic.
|
|
429
|
-
*/
|
|
430
|
-
arrayContaining<E = any>(arr: E[]): any;
|
|
431
|
-
/**
|
|
432
|
-
* Verifies that a certain number of assertions are called during a test.
|
|
433
|
-
* This is often useful when testing asynchronous code, in order to
|
|
434
|
-
* make sure that assertions in a callback actually got called.
|
|
435
|
-
*/
|
|
436
|
-
assertions(num: number): void;
|
|
437
|
-
/**
|
|
438
|
-
* Verifies that at least one assertion is called during a test.
|
|
439
|
-
* This is often useful when testing asynchronous code, in order to
|
|
440
|
-
* make sure that assertions in a callback actually got called.
|
|
441
|
-
*/
|
|
442
|
-
hasAssertions(): void;
|
|
443
|
-
/**
|
|
444
|
-
* You can use `expect.extend` to add your own matchers to Jest.
|
|
445
|
-
*/
|
|
446
|
-
extend(obj: ExpectExtendMap): void;
|
|
447
|
-
/**
|
|
448
|
-
* Matches any object that recursively matches the provided keys.
|
|
449
|
-
* This is often handy in conjunction with other asymmetric matchers.
|
|
450
|
-
*
|
|
451
|
-
* Optionally, you can provide a type for the object via a generic.
|
|
452
|
-
* This ensures that the object contains the desired structure.
|
|
453
|
-
*/
|
|
454
|
-
objectContaining<E = {}>(obj: E): any;
|
|
455
|
-
/**
|
|
456
|
-
* Matches any string that contains the exact provided string
|
|
457
|
-
*/
|
|
458
|
-
stringMatching(str: string | RegExp): any;
|
|
459
|
-
/**
|
|
460
|
-
* Matches any received string that contains the exact expected string
|
|
461
|
-
*/
|
|
462
|
-
stringContaining(str: string): any;
|
|
463
|
-
|
|
464
|
-
not: InverseAsymmetricMatchers;
|
|
465
|
-
|
|
466
|
-
setState(state: object): void;
|
|
467
|
-
}
|
|
468
|
-
interface InverseAsymmetricMatchers {
|
|
469
|
-
/**
|
|
470
|
-
* `expect.not.arrayContaining(array)` matches a received array which
|
|
471
|
-
* does not contain all of the elements in the expected array. That is,
|
|
472
|
-
* the expected array is not a subset of the received array. It is the
|
|
473
|
-
* inverse of `expect.arrayContaining`.
|
|
474
|
-
*
|
|
475
|
-
* Optionally, you can provide a type for the elements via a generic.
|
|
476
|
-
*/
|
|
477
|
-
arrayContaining<E = any>(arr: E[]): any;
|
|
478
|
-
/**
|
|
479
|
-
* `expect.not.objectContaining(object)` matches any received object
|
|
480
|
-
* that does not recursively match the expected properties. That is, the
|
|
481
|
-
* expected object is not a subset of the received object. Therefore,
|
|
482
|
-
* it matches a received object which contains properties that are not
|
|
483
|
-
* in the expected object. It is the inverse of `expect.objectContaining`.
|
|
484
|
-
*
|
|
485
|
-
* Optionally, you can provide a type for the object via a generic.
|
|
486
|
-
* This ensures that the object contains the desired structure.
|
|
487
|
-
*/
|
|
488
|
-
objectContaining<E = {}>(obj: E): any;
|
|
489
|
-
/**
|
|
490
|
-
* `expect.not.stringMatching(string | regexp)` matches the received
|
|
491
|
-
* string that does not match the expected regexp. It is the inverse of
|
|
492
|
-
* `expect.stringMatching`.
|
|
493
|
-
*/
|
|
494
|
-
stringMatching(str: string | RegExp): any;
|
|
495
|
-
/**
|
|
496
|
-
* `expect.not.stringContaining(string)` matches the received string
|
|
497
|
-
* that does not contain the exact expected string. It is the inverse of
|
|
498
|
-
* `expect.stringContaining`.
|
|
499
|
-
*/
|
|
500
|
-
stringContaining(str: string): any;
|
|
501
|
-
}
|
|
502
|
-
}
|