expect-webdriverio 5.4.3 → 5.6.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.
@@ -4,15 +4,527 @@ type Test = import('@wdio/types').Frameworks.Test
4
4
  type TestResult = import('@wdio/types').Frameworks.TestResult
5
5
  type PickleStep = import('@wdio/types').Frameworks.PickleStep
6
6
  type Scenario = import('@wdio/types').Frameworks.Scenario
7
+
7
8
  type SnapshotResult = import('@vitest/snapshot').SnapshotResult
8
9
  type SnapshotUpdateState = import('@vitest/snapshot').SnapshotUpdateState
9
10
 
11
+ type ChainablePromiseElement = import('webdriverio').ChainablePromiseElement
12
+ type ChainablePromiseArray = import('webdriverio').ChainablePromiseArray
13
+
14
+ type ExpectLibAsymmetricMatchers = import('expect').AsymmetricMatchers
15
+ type ExpectLibAsymmetricMatcher<T> = import('expect').AsymmetricMatcher<T>
16
+ type ExpectLibMatchers<R extends void | Promise<void>, T> = import('expect').Matchers<R, T>
17
+ type ExpectLibExpect = import('expect').Expect
18
+ type ExpectLibInverse<Matchers> = import('expect').Inverse<Matchers>
19
+ type ExpectLibSyncExpectationResult = import('expect').SyncExpectationResult
20
+ type ExpectLibAsyncExpectationResult = import('expect').AsyncExpectationResult
21
+ type ExpectLibExpectationResult = import('expect').ExpectationResult
22
+ type ExpectLibMatcherContext = import('expect').MatcherContext
23
+
24
+ // Extracted from the expect library, this is the type of the matcher function used in the expect library.
25
+ type RawMatcherFn<Context extends ExpectLibMatcherContext = ExpectLibMatcherContext> = {
26
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
27
+ (this: Context, actual: any, ...expected: Array<any>): ExpectLibExpectationResult;
28
+ }
29
+
30
+ /**
31
+ * Real Promise and wdio chainable promise types.
32
+ */
33
+ type WdioPromiseLike<T = unknown> = PromiseLike<T> | ChainablePromiseElement | ChainablePromiseArray
34
+ type ElementPromise = Promise<WebdriverIO.Element>
35
+ type ElementArrayPromise = Promise<WebdriverIO.ElementArray>
36
+
37
+ /**
38
+ * Only Wdio real promise
39
+ */
40
+ type WdioOnlyPromiseLike = ElementPromise | ElementArrayPromise | ChainablePromiseElement | ChainablePromiseArray
41
+
42
+ /**
43
+ * Only wdio real promise or potential promise usage on element or element array or browser
44
+ */
45
+ type WdioOnlyMaybePromiseLike = ElementPromise | ElementArrayPromise | ChainablePromiseElement | ChainablePromiseArray | WebdriverIO.Browser | WebdriverIO.Element | WebdriverIO.ElementArray
46
+
47
+ /**
48
+ * Note we are defining Matchers outside of the namespace as done in jest library until we can make every typing work correctly.
49
+ * Once we have all types working, we could check to bring those back into the `ExpectWebdriverIO` namespace.
50
+ */
51
+
52
+ /**
53
+ * Type helpers to be able to targets specific types mostly used in conjunctions with the Type of the `actual` parameter of the `expect`
54
+ */
55
+ type ElementOrArrayLike = ElementLike | ElementArrayLike
56
+ type ElementLike = WebdriverIO.Element | ChainablePromiseElement
57
+ type ElementArrayLike = WebdriverIO.ElementArray | ChainablePromiseArray
58
+ type MockPromise = Promise<WebdriverIO.Mock>
59
+
60
+ /**
61
+ * Type helpers allowing to use the function when the expect(actual: T) is of the expected type T.
62
+ */
63
+ type FnWhenBrowser<ActualT, Fn> = ActualT extends WebdriverIO.Browser ? Fn : never
64
+ type FnWhenElementOrArrayLike<ActualT, Fn> = ActualT extends ElementOrArrayLike ? Fn : never
65
+ type FnWhenElementArrayLike<ActualT, Fn> = ActualT extends ElementArrayLike ? Fn : never
66
+
67
+ /**
68
+ * Same as the other but because of Jasmine and it's expectAsync typing which does not force T to be a promise, then we need to account for `WebdriverIO.Mock
69
+ */
70
+ type FnWhenMock<ActualT, Fn> = ActualT extends MockPromise | WebdriverIO.Mock ? Fn : never
71
+
72
+ /**
73
+ * Matchers dedicated to Wdio Browser.
74
+ * When asserting on a browser's properties requiring to be awaited, the return type is a Promise.
75
+ * When actual is not a browser, the return type is never, so the function cannot be used.
76
+ */
77
+ interface WdioBrowserMatchers<_R, ActualT>{
78
+ /**
79
+ * `WebdriverIO.Browser` -> `getUrl`
80
+ */
81
+ toHaveUrl: FnWhenBrowser<ActualT, (url: string | RegExp | ExpectWebdriverIO.PartialMatcher<string>, options?: ExpectWebdriverIO.StringOptions) => Promise<void>>
82
+
83
+ /**
84
+ * `WebdriverIO.Browser` -> `getTitle`
85
+ */
86
+ toHaveTitle: FnWhenBrowser<ActualT, (title: string | RegExp | ExpectWebdriverIO.PartialMatcher<string>, options?: ExpectWebdriverIO.StringOptions) => Promise<void>>
87
+
88
+ /**
89
+ * `WebdriverIO.Browser` -> `execute`
90
+ */
91
+ toHaveClipboardText: FnWhenBrowser<ActualT, (clipboardText: string | RegExp | ExpectWebdriverIO.PartialMatcher<string>, options?: ExpectWebdriverIO.StringOptions) => Promise<void>>
92
+ }
93
+
94
+ /**
95
+ * Matchers dedicated to Network Mocking.
96
+ * When asserting we wait for the result with `await waitUntil()`, therefore the return type needs to be a Promise.
97
+ * When actual is not a WebdriverIO.Mock, the return type is never, so the function cannot be used.
98
+ */
99
+ interface WdioNetworkMatchers<_R, ActualT> {
100
+ /**
101
+ * Check that `WebdriverIO.Mock` was called
102
+ */
103
+ toBeRequested: FnWhenMock<ActualT, (options?: ExpectWebdriverIO.CommandOptions) => Promise<void>>
104
+ /**
105
+ * Check that `WebdriverIO.Mock` was called N times
106
+ */
107
+ toBeRequestedTimes: FnWhenMock<ActualT, (times: number | ExpectWebdriverIO.NumberOptions, options?: ExpectWebdriverIO.NumberOptions) => Promise<void>>
108
+
109
+ /**
110
+ * Check that `WebdriverIO.Mock` was called with the specific parameters
111
+ */
112
+ toBeRequestedWith: FnWhenMock<ActualT, (requestedWith: ExpectWebdriverIO.RequestedWith, options?: ExpectWebdriverIO.CommandOptions) => Promise<void>>
113
+ }
114
+
115
+ /**
116
+ * Matchers dedicated to WebdriverIO Element or ElementArray (or chainable).
117
+ * When asserting on an element or element array's properties requiring to be awaited, the return type is a Promise.
118
+ * When actual is neither of WebdriverIO.Element, WebdriverIO.ElementArray, ChainableElement, ChainableElementArray, the return type is never, so the function cannot be used.
119
+ */
120
+ interface WdioElementOrArrayMatchers<_R, ActualT = unknown> {
121
+ // ===== $ or $$ =====
122
+ /**
123
+ * `WebdriverIO.Element` -> `isDisplayed`
124
+ */
125
+ toBeDisplayed: FnWhenElementOrArrayLike<ActualT, (options?: ExpectWebdriverIO.CommandOptions) => Promise<void>>
126
+
127
+ /**
128
+ * `WebdriverIO.Element` -> `isExisting`
129
+ */
130
+ toExist: FnWhenElementOrArrayLike<ActualT, (options?: ExpectWebdriverIO.CommandOptions) => Promise<void>>
131
+
132
+ /**
133
+ * `WebdriverIO.Element` -> `isExisting`
134
+ */
135
+ toBePresent: FnWhenElementOrArrayLike<ActualT, (options?: ExpectWebdriverIO.CommandOptions) => Promise<void>>
136
+
137
+ /**
138
+ * `WebdriverIO.Element` -> `isExisting`
139
+ */
140
+ toBeExisting: FnWhenElementOrArrayLike<ActualT, (options?: ExpectWebdriverIO.CommandOptions) => Promise<void>>
141
+
142
+ /**
143
+ * `WebdriverIO.Element` -> `getAttribute`
144
+ */
145
+ toHaveAttribute: FnWhenElementOrArrayLike<ActualT, (
146
+ attribute: string, value?: string | RegExp | ExpectWebdriverIO.PartialMatcher<string>,
147
+ options?: ExpectWebdriverIO.StringOptions)
148
+ => Promise<void>>
149
+
150
+ /**
151
+ * `WebdriverIO.Element` -> `getAttribute`
152
+ */
153
+ toHaveAttr: FnWhenElementOrArrayLike<ActualT, (
154
+ attribute: string, value?: string | RegExp | ExpectWebdriverIO.PartialMatcher<string>,
155
+ options?: ExpectWebdriverIO.StringOptions
156
+ ) => Promise<void>>
157
+
158
+ /**
159
+ * `WebdriverIO.Element` -> `getAttribute` class
160
+ * @deprecated since v1.3.1 - use `toHaveElementClass` instead.
161
+ */
162
+ toHaveClass: FnWhenElementOrArrayLike<ActualT, (
163
+ className: string | RegExp | ExpectWebdriverIO.PartialMatcher<string>,
164
+ options?: ExpectWebdriverIO.StringOptions
165
+ ) => Promise<void>>
166
+
167
+ /**
168
+ * `WebdriverIO.Element` -> `getAttribute` class
169
+ *
170
+ * Checks if an element has the specified class or matches any of the provided class patterns.
171
+ * @param className - The class name(s) or pattern(s) to match against.
172
+ * @param options - Optional settings that can be passed to the function.
173
+ *
174
+ * **Usage**
175
+ * ```js
176
+ * // Check if an element has the class 'btn'
177
+ * await expect(element).toHaveElementClass('btn');
178
+ *
179
+ * // Check if an element has any of the specified classes
180
+ * await expect(element).toHaveElementClass(['btn', 'btn-large']);
181
+ * ```
182
+ */
183
+ toHaveElementClass: FnWhenElementOrArrayLike<ActualT, (
184
+ className: string | RegExp | Array<string | RegExp> | ExpectWebdriverIO.PartialMatcher<string>,
185
+ options?: ExpectWebdriverIO.StringOptions
186
+ ) => Promise<void>>
187
+
188
+ /**
189
+ * `WebdriverIO.Element` -> `getProperty`
190
+ */
191
+ toHaveElementProperty: FnWhenElementOrArrayLike<ActualT, (
192
+ property: string | RegExp | ExpectWebdriverIO.PartialMatcher<string>,
193
+ value?: unknown,
194
+ options?: ExpectWebdriverIO.StringOptions
195
+ ) => Promise<void>>
196
+
197
+ /**
198
+ * `WebdriverIO.Element` -> `getProperty` value
199
+ */
200
+ toHaveValue: FnWhenElementOrArrayLike<ActualT, (
201
+ value: string | RegExp | ExpectWebdriverIO.PartialMatcher<string>,
202
+ options?: ExpectWebdriverIO.StringOptions
203
+ ) => Promise<void>>
204
+
205
+ /**
206
+ * `WebdriverIO.Element` -> `isClickable`
207
+ */
208
+ toBeClickable: FnWhenElementOrArrayLike<ActualT, (options?: ExpectWebdriverIO.CommandOptions) => Promise<void>>
209
+
210
+ /**
211
+ * `WebdriverIO.Element` -> `!isEnabled`
212
+ */
213
+ toBeDisabled: FnWhenElementOrArrayLike<ActualT, (options?: ExpectWebdriverIO.CommandOptions) => Promise<void>>
214
+
215
+ /**
216
+ * `WebdriverIO.Element` -> `isDisplayedInViewport`
217
+ */
218
+ toBeDisplayedInViewport: FnWhenElementOrArrayLike<ActualT, (options?: ExpectWebdriverIO.CommandOptions) => Promise<void>>
219
+
220
+ /**
221
+ * `WebdriverIO.Element` -> `isEnabled`
222
+ */
223
+ toBeEnabled: FnWhenElementOrArrayLike<ActualT, (options?: ExpectWebdriverIO.CommandOptions) => Promise<void>>
224
+
225
+ /**
226
+ * `WebdriverIO.Element` -> `isFocused`
227
+ */
228
+ toBeFocused: FnWhenElementOrArrayLike<ActualT, (options?: ExpectWebdriverIO.CommandOptions) => Promise<void>>
229
+
230
+ /**
231
+ * `WebdriverIO.Element` -> `isSelected`
232
+ */
233
+ toBeSelected: FnWhenElementOrArrayLike<ActualT, (options?: ExpectWebdriverIO.CommandOptions) => Promise<void>>
234
+
235
+ /**
236
+ * `WebdriverIO.Element` -> `isSelected`
237
+ */
238
+ toBeChecked: FnWhenElementOrArrayLike<ActualT, (options?: ExpectWebdriverIO.CommandOptions) => Promise<void>>
239
+
240
+ /**
241
+ * `WebdriverIO.Element` -> `$$('./*').length`
242
+ * supports less / greater then or equals to be passed in options
243
+ */
244
+ toHaveChildren: FnWhenElementOrArrayLike<ActualT, (
245
+ size?: number | ExpectWebdriverIO.NumberOptions,
246
+ options?: ExpectWebdriverIO.NumberOptions
247
+ ) => Promise<void>>
248
+
249
+ /**
250
+ * `WebdriverIO.Element` -> `getAttribute` href
251
+ */
252
+ toHaveHref: FnWhenElementOrArrayLike<ActualT, (
253
+ href: string | RegExp | ExpectWebdriverIO.PartialMatcher<string>,
254
+ options?: ExpectWebdriverIO.StringOptions
255
+ ) => Promise<void>>
256
+
257
+ /**
258
+ * `WebdriverIO.Element` -> `getAttribute` href
259
+ */
260
+ toHaveLink: FnWhenElementOrArrayLike<ActualT, (
261
+ href: string | RegExp | ExpectWebdriverIO.PartialMatcher<string>,
262
+ options?: ExpectWebdriverIO.StringOptions
263
+ ) => Promise<void>>
264
+
265
+ /**
266
+ * `WebdriverIO.Element` -> `getProperty` value
267
+ */
268
+ toHaveId: FnWhenElementOrArrayLike<ActualT, (
269
+ id: string | RegExp | ExpectWebdriverIO.PartialMatcher<string>,
270
+ options?: ExpectWebdriverIO.StringOptions
271
+ ) => Promise<void>>
272
+
273
+ /**
274
+ * `WebdriverIO.Element` -> `getSize` value
275
+ */
276
+ toHaveSize: FnWhenElementOrArrayLike<ActualT, (
277
+ size: { height: number; width: number },
278
+ options?: ExpectWebdriverIO.StringOptions
279
+ ) => Promise<void>>
280
+
281
+ /**
282
+ * `WebdriverIO.Element` -> `getText`
283
+ * Element's text equals the text provided
284
+ *
285
+ * @param text - The expected text to match.
286
+ * @param options - Optional settings that can be passed to the function.
287
+ *
288
+ * **Usage**
289
+ *
290
+ * ```js
291
+ * // Check if an element has the text
292
+ * const elem = await $('.container')
293
+ * await expect(elem).toHaveText('Next-gen browser and mobile automation test framework for Node.js')
294
+ *
295
+ * // Check if an element array contains the specified text
296
+ * const elem = await $$('ul > li')
297
+ * await expect(elem).toHaveText(['Coffee', 'Tea', 'Milk'])
298
+ * ```
299
+ */
300
+ toHaveText: FnWhenElementOrArrayLike<ActualT, (
301
+ text: string | RegExp | ExpectWebdriverIO.PartialMatcher<string> | Array<string | RegExp | ExpectWebdriverIO.PartialMatcher<string>>,
302
+ options?: ExpectWebdriverIO.StringOptions
303
+ ) => Promise<void>>
304
+
305
+ /**
306
+ * `WebdriverIO.Element` -> `getHTML`
307
+ * Element's html equals the html provided
308
+ */
309
+ toHaveHTML: FnWhenElementOrArrayLike<ActualT, (
310
+ html: string | RegExp | ExpectWebdriverIO.PartialMatcher<string> | Array<string | RegExp>,
311
+ options?: ExpectWebdriverIO.StringOptions
312
+ ) => Promise<void>>
313
+
314
+ /**
315
+ * `WebdriverIO.Element` -> `getComputedLabel`
316
+ * Element's computed label equals the computed label provided
317
+ */
318
+ toHaveComputedLabel: FnWhenElementOrArrayLike<ActualT, (
319
+ computedLabel: string | RegExp | ExpectWebdriverIO.PartialMatcher<string> | Array<string | RegExp>,
320
+ options?: ExpectWebdriverIO.StringOptions
321
+ ) => Promise<void>>
322
+
323
+ /**
324
+ * `WebdriverIO.Element` -> `getComputedRole`
325
+ * Element's computed role equals the computed role provided
326
+ */
327
+ toHaveComputedRole: FnWhenElementOrArrayLike<ActualT, (
328
+ computedRole: string | RegExp | ExpectWebdriverIO.PartialMatcher<string> | Array<string | RegExp>,
329
+ options?: ExpectWebdriverIO.StringOptions
330
+ ) => Promise<void>>
331
+
332
+ /**
333
+ * `WebdriverIO.Element` -> `getSize('width')`
334
+ * Element's width equals the width provided
335
+ */
336
+ toHaveWidth: FnWhenElementOrArrayLike<ActualT, (width: number, options?: ExpectWebdriverIO.CommandOptions) => Promise<void>>
337
+
338
+ /**
339
+ * `WebdriverIO.Element` -> `getSize('height')` or `getSize()`
340
+ * Checks if the element's height equals the given number, or its size equals the given object.
341
+ *
342
+ * @param heightOrSize - Either a number (height) or an object with height and width.
343
+ * @param options - Optional command options.
344
+ *
345
+ * **Usage Example:**
346
+ * ```js
347
+ * await expect(element).toHaveHeight(42)
348
+ * await expect(element).toHaveHeight({ height: 42, width: 42 })
349
+ * ```
350
+ */
351
+ toHaveHeight: FnWhenElementOrArrayLike<ActualT, (
352
+ heightOrSize: number | { height: number; width: number },
353
+ options?: ExpectWebdriverIO.CommandOptions
354
+ ) => Promise<void>>
355
+
356
+ /**
357
+ * `WebdriverIO.Element` -> `getAttribute("style")`
358
+ */
359
+ toHaveStyle: FnWhenElementOrArrayLike<ActualT, (style: { [key: string]: string }, options?: ExpectWebdriverIO.StringOptions) => Promise<void>>
360
+ }
361
+
362
+ /**
363
+ * Matchers dedicated to WebdriverIO ElementArray (or its chainable).
364
+ * When asserting on each element's properties requiring awaiting, then return type is a Promise.
365
+ * When actual is not of WebdriverIO.ElementArray nor ChainableElementArray, the return type is never, so the function cannot be used.
366
+ */
367
+ interface WdioElementArrayOnlyMatchers<_R, ActualT = unknown> {
368
+ // ===== $$ only =====
369
+ /**
370
+ * `WebdriverIO.ElementArray` -> `$$('...').length`
371
+ * supports less / greater then or equals to be passed in options
372
+ */
373
+ toBeElementsArrayOfSize: FnWhenElementArrayLike<ActualT, (
374
+ size: number | ExpectWebdriverIO.NumberOptions,
375
+ options?: ExpectWebdriverIO.NumberOptions
376
+ ) => Promise<void> & Promise<WebdriverIO.ElementArray>>
377
+ }
378
+
379
+ /**
380
+ * Matchers supporting basic snapshot tests as well as DOM snapshot testing.
381
+ * When the actual is a WebdriverIO.Element, we need to await the `outerHTML` therefore the return type is a Promise.
382
+ *
383
+ * ⚠️ these matchers overload the similar matchers from jest-expect library.
384
+ * Therefore, they also need to be redefined in the jest.d.ts file so correctly overload the matchers from the Jest namespace.
385
+ * @see jest.d.ts
386
+ */
387
+ interface WdioJestOverloadedMatchers<_R, ActualT> {
388
+ /**
389
+ * snapshot matcher
390
+ * @param label optional snapshot label
391
+ */
392
+ toMatchSnapshot(label?: string): ActualT extends WdioPromiseLike ? Promise<void> : void;
393
+ /**
394
+ * inline snapshot matcher
395
+ * @param snapshot snapshot string (autogenerated if not specified)
396
+ * @param label optional snapshot label
397
+ */
398
+ toMatchInlineSnapshot(snapshot?: string, label?: string): ActualT extends WdioPromiseLike ? Promise<void> : void;
399
+ }
400
+
401
+ /**
402
+ * All the specific WebDriverIO only matchers, excluding the generic matchers from the expect library.
403
+ */
404
+ type WdioCustomMatchers<R, ActualT> = WdioJestOverloadedMatchers<R, ActualT> & WdioBrowserMatchers<R, ActualT> & WdioElementOrArrayMatchers<R, ActualT> & WdioElementArrayOnlyMatchers<R, ActualT> & WdioNetworkMatchers<R, ActualT>
405
+
406
+ /**
407
+ * All the matchers that WebdriverIO Library supports including the generic matchers from the expect library.
408
+ */
409
+ type WdioMatchers<R extends void | Promise<void>, ActualT> = WdioCustomMatchers<R, ActualT> & ExpectLibMatchers<R, ActualT>
410
+
411
+ /**
412
+ * Expects specific to WebdriverIO, excluding the generic expect matchers.
413
+ */
414
+ interface WdioCustomExpect {
415
+ /**
416
+ * Creates a soft assertion wrapper around standard expect
417
+ * Soft assertions record failures but don't throw errors immediately
418
+ * All failures are collected and reported at the end of the test
419
+ * Note: Until fixed, soft only support wdio custom matchers, and not the `expect` library matchers. Moreover, it always returns a Promise.
420
+ */
421
+ soft<T = unknown>(actual: T): T extends PromiseLike<unknown> ? ExpectWebdriverIO.MatchersAndInverse<Promise<void>, T> & ExpectWebdriverIO.PromiseMatchers<T> : ExpectWebdriverIO.MatchersAndInverse<void, T>;
422
+
423
+ /**
424
+ * Get all current soft assertion failures
425
+ */
426
+ getSoftFailures(testId?: string): ExpectWebdriverIO.SoftFailure[]
427
+
428
+ /**
429
+ * Manually assert all soft failures (throws an error if any failures exist)
430
+ */
431
+ assertSoftFailures(testId?: string): void
432
+
433
+ /**
434
+ * Clear all current soft assertion failures
435
+ */
436
+ clearSoftFailures(testId?: string): void
437
+ }
438
+
439
+ /**
440
+ * Expects supported by the expect-webdriverio library, including the generic expect matchers.
441
+ */
442
+ type WdioExpect = WdioCustomExpect & ExpectLibExpect
443
+
444
+ /**
445
+ * Asymmetric matchers supported by the expect-webdriverio library.
446
+ * The type is the same as the one from the expect library, but we need to redefine it to have it available in the `ExpectWebdriverIO` namespace.
447
+ */
448
+ type WdioAsymmetricMatchers = ExpectLibAsymmetricMatchers
449
+
450
+ /**
451
+ * Implementation of the asymmetric matcher. Equivalent as the PartialMatcher but with sample used by implementations.
452
+ * For the runtime but not the typing.
453
+ */
454
+ type WdioAsymmetricMatcher<R> = ExpectWebdriverIO.PartialMatcher<R> & {
455
+ // Overwrite protected properties of expect.AsymmetricMatcher to access them
456
+ sample: R;
457
+ }
458
+
10
459
  declare namespace ExpectWebdriverIO {
460
+ /**
461
+ * When importing expect from 'expect-webdriverio', instead of using globals this is the one used.
462
+ * Note: Using a const instead of a function, else we cannot use asymmetric matcher like expect.anything().
463
+ */
11
464
  const expect: ExpectWebdriverIO.Expect
465
+
466
+ /**
467
+ * Used by the webdriverio main project to configure the matchers in the runner.
468
+ */
12
469
  function setOptions(options: DefaultOptions): void
13
470
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
471
  function getConfig(): any
15
472
 
473
+ /**
474
+ * The below block are overloaded types from the expect library.
475
+ * They are required to show "everything" under the `ExpectWebdriverIO` namespace.
476
+ * They are also required to be be able to declare custom asymmetric/normal matchers under the `ExpectWebdriverIO` namespace.
477
+ * The type `T` must stay named `T` to correctly overload the expect function from the expect library.
478
+ */
479
+
480
+ /**
481
+ * Expect defining the custom wdio expect and also pulling on asymmetric matchers.
482
+ * `AsymmetricMatchers` and `Inverse<AsymmetricMatchers>` needs to be defined and be before the `expect` library Expect (aka `WdioExpect`).
483
+ * The above allows to have custom asymmetric matchers under the `ExpectWebdriverIO` namespace.
484
+ */
485
+ interface Expect extends ExpectWebdriverIO.AsymmetricMatchers, ExpectLibInverse<ExpectWebdriverIO.InverseAsymmetricMatchers>, WdioExpect {
486
+ /**
487
+ * The `expect` function is used every time you want to test a value.
488
+ * You will rarely call `expect` by itself.
489
+ *
490
+ * expect function declaration contains two generics:
491
+ * - T: the type of the actual value, e.g. any type, not just WebdriverIO.Browser or WebdriverIO.Element
492
+ * - R: the type of the return value, e.g. Promise<void> or void
493
+ *
494
+ * Note: The function must stay here in the namespace to overwrite correctly the expect function from the expect library.
495
+ *
496
+ * @param actual The value to apply matchers against.
497
+ */
498
+ <T = unknown>(actual: T): T extends PromiseLike<unknown> ? ExpectWebdriverIO.MatchersAndInverse<void, T> & ExpectWebdriverIO.PromiseMatchers<T> : ExpectWebdriverIO.MatchersAndInverse<void, T>;
499
+ }
500
+
501
+ interface Matchers<R extends void | Promise<void>, T> extends WdioMatchers<R, T> {}
502
+
503
+ interface AsymmetricMatchers extends WdioAsymmetricMatchers {}
504
+
505
+ interface InverseAsymmetricMatchers extends Omit<ExpectWebdriverIO.AsymmetricMatchers, 'anything' | 'any'> {}
506
+
507
+ /**
508
+ * End of block overloading types from the expect library.
509
+ */
510
+
511
+ type MatchersAndInverse<R extends void | Promise<void>, ActualT> = ExpectWebdriverIO.Matchers<R, ActualT> & ExpectLibInverse<ExpectWebdriverIO.Matchers<R, ActualT>>
512
+
513
+ /**
514
+ * Take from expect library
515
+ */
516
+ type PromiseMatchers<T = unknown> = {
517
+ /**
518
+ * Unwraps the reason of a rejected promise so any other matcher can be chained.
519
+ * If the promise is fulfilled the assertion fails.
520
+ */
521
+ rejects: MatchersAndInverse<Promise<void>, T>;
522
+ /**
523
+ * Unwraps the value of a fulfilled promise so any other matcher can be chained.
524
+ * If the promise is rejected the assertion fails.
525
+ */
526
+ resolves: MatchersAndInverse<Promise<void>, T>;
527
+ }
16
528
  interface SnapshotServiceArgs {
17
529
  updateState?: SnapshotUpdateState
18
530
  resolveSnapshotPath?: (path: string, extension: string) => string
@@ -47,7 +559,7 @@ declare namespace ExpectWebdriverIO {
47
559
 
48
560
  class SoftAssertionService implements ServiceInstance {
49
561
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
50
- constructor(serviceOptions?: SoftAssertionServiceOptions, capabilities?: any, config?: any)
562
+ constructor(serviceOptions?: SoftAssertionServiceOptions, capabilities?: unknown, config?: any)
51
563
  beforeTest(test: Test): void
52
564
  beforeStep(step: PickleStep, scenario: Scenario): void
53
565
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -55,20 +567,15 @@ declare namespace ExpectWebdriverIO {
55
567
  afterStep(step: PickleStep, scenario: Scenario, result: { passed: boolean, error?: Error }): void
56
568
  }
57
569
 
58
- interface AssertionResult {
59
- pass: boolean
60
- message(): string
61
- }
570
+ interface AssertionResult extends ExpectLibSyncExpectationResult {}
571
+ type AsyncAssertionResult = ExpectLibAsyncExpectationResult
62
572
 
63
- const matchers: Map<
64
- string,
65
- (
66
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
67
- actual: any,
68
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
69
- ...expected: any[]
70
- ) => Promise<AssertionResult>
71
- >
573
+ /**
574
+ * Used by the wdio main project to configure the matchers in the runner when using Jasmine or Jest.
575
+ * Equivalent as `MatchersObject` from the expect library.
576
+ * @see https://github.com/jestjs/jest/blob/fd3d6cf9fe416b549a74b6577e5e1ea1130e3659/packages/expect/src/types.ts#L43C13-L43C27
577
+ */
578
+ const matchers: Map<string, RawMatcherFn>
72
579
 
73
580
  interface AssertionHookParams {
74
581
  /**
@@ -195,290 +702,28 @@ declare namespace ExpectWebdriverIO {
195
702
  gte?: number
196
703
  }
197
704
 
198
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
199
- interface Matchers<R, T> {
200
- // ===== $ or $$ =====
201
- /**
202
- * `WebdriverIO.Element` -> `isDisplayed`
203
- */
204
- toBeDisplayed(options?: ExpectWebdriverIO.CommandOptions): R
205
-
206
- /**
207
- * `WebdriverIO.Element` -> `isExisting`
208
- */
209
- toExist(options?: ExpectWebdriverIO.CommandOptions): R
210
- /**
211
- * `WebdriverIO.Element` -> `isExisting`
212
- */
213
- toBePresent(options?: ExpectWebdriverIO.CommandOptions): R
214
- /**
215
- * `WebdriverIO.Element` -> `isExisting`
216
- */
217
- toBeExisting(options?: ExpectWebdriverIO.CommandOptions): R
218
-
219
- /**
220
- * `WebdriverIO.Element` -> `getAttribute`
221
- */
222
- toHaveAttribute(
223
- attribute: string,
224
- value?: string | RegExp | ExpectWebdriverIO.PartialMatcher,
225
- options?: ExpectWebdriverIO.StringOptions
226
- ): R
227
- /**
228
- * `WebdriverIO.Element` -> `getAttribute`
229
- */
230
- toHaveAttr(attribute: string, value?: string | RegExp | ExpectWebdriverIO.PartialMatcher, options?: ExpectWebdriverIO.StringOptions): R
231
-
232
- /**
233
- * `WebdriverIO.Element` -> `getAttribute` class
234
- * @deprecated since v1.3.1 - use `toHaveElementClass` instead.
235
- */
236
- toHaveClass(className: string | RegExp | ExpectWebdriverIO.PartialMatcher, options?: ExpectWebdriverIO.StringOptions): R
237
-
238
- /**
239
- * `WebdriverIO.Element` -> `getAttribute` class
240
- *
241
- * Checks if an element has the specified class or matches any of the provided class patterns.
242
- * @param className - The class name(s) or pattern(s) to match against.
243
- * @param options - Optional settings that can be passed to the function.
244
- *
245
- * **Usage**
246
- * ```js
247
- * // Check if an element has the class 'btn'
248
- * await expect(element).toHaveElementClass('btn')
249
- *
250
- * // Check if an element has any of the specified classes
251
- * await expect(element).toHaveElementClass(['btn', 'btn-large'])
252
- * ```
253
- */
254
- toHaveElementClass(className: string | RegExp | Array<string | RegExp> | ExpectWebdriverIO.PartialMatcher, options?: ExpectWebdriverIO.StringOptions): R
255
-
256
- /**
257
- * `WebdriverIO.Element` -> `getProperty`
258
- */
259
- toHaveElementProperty(
260
- property: string | RegExp | ExpectWebdriverIO.PartialMatcher,
261
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
262
- value?: any,
263
- options?: ExpectWebdriverIO.StringOptions
264
- ): R
265
-
266
- /**
267
- * `WebdriverIO.Element` -> `getProperty` value
268
- */
269
- toHaveValue(value: string | RegExp | ExpectWebdriverIO.PartialMatcher, options?: ExpectWebdriverIO.StringOptions): R
270
-
271
- /**
272
- * `WebdriverIO.Element` -> `isClickable`
273
- */
274
- toBeClickable(options?: ExpectWebdriverIO.StringOptions): R
275
-
276
- /**
277
- * `WebdriverIO.Element` -> `!isEnabled`
278
- */
279
- toBeDisabled(options?: ExpectWebdriverIO.StringOptions): R
280
-
281
- /**
282
- * `WebdriverIO.Element` -> `isDisplayedInViewport`
283
- */
284
- toBeDisplayedInViewport(options?: ExpectWebdriverIO.StringOptions): R
285
-
286
- /**
287
- * `WebdriverIO.Element` -> `isEnabled`
288
- */
289
- toBeEnabled(options?: ExpectWebdriverIO.StringOptions): R
290
-
291
- /**
292
- * `WebdriverIO.Element` -> `isFocused`
293
- */
294
- toBeFocused(options?: ExpectWebdriverIO.StringOptions): R
295
-
296
- /**
297
- * `WebdriverIO.Element` -> `isSelected`
298
- */
299
- toBeSelected(options?: ExpectWebdriverIO.StringOptions): R
300
-
301
- /**
302
- * `WebdriverIO.Element` -> `isSelected`
303
- */
304
- toBeChecked(options?: ExpectWebdriverIO.StringOptions): R
305
-
306
- /**
307
- * `WebdriverIO.Element` -> `$$('./*').length`
308
- * supports less / greater then or equals to be passed in options
309
- */
310
- toHaveChildren(
311
- size?: number | ExpectWebdriverIO.NumberOptions,
312
- options?: ExpectWebdriverIO.NumberOptions
313
- ): R
314
-
315
- /**
316
- * `WebdriverIO.Element` -> `getAttribute` href
317
- */
318
- toHaveHref(href: string | RegExp | ExpectWebdriverIO.PartialMatcher, options?: ExpectWebdriverIO.StringOptions): R
319
- /**
320
- * `WebdriverIO.Element` -> `getAttribute` href
321
- */
322
- toHaveLink(href: string | RegExp | ExpectWebdriverIO.PartialMatcher, options?: ExpectWebdriverIO.StringOptions): R
323
-
324
- /**
325
- * `WebdriverIO.Element` -> `getProperty` value
326
- */
327
- toHaveId(id: string | RegExp | ExpectWebdriverIO.PartialMatcher, options?: ExpectWebdriverIO.StringOptions): R
328
-
329
- /**
330
- * `WebdriverIO.Element` -> `getSize` value
331
- */
332
- toHaveSize(size: { height: number; width: number }, options?: ExpectWebdriverIO.StringOptions): R
333
-
334
- /**
335
- * `WebdriverIO.Element` -> `getText`
336
- * Element's text equals the text provided
337
- *
338
- * @param text - The expected text to match.
339
- * @param options - Optional settings that can be passed to the function.
340
- *
341
- * **Usage**
342
- *
343
- * ```js
344
- * // Check if an element has the text
345
- * const elem = await $('.container')
346
- * await expect(elem).toHaveText('Next-gen browser and mobile automation test framework for Node.js')
347
- *
348
- * // Check if an element array contains the specified text
349
- * const elem = await $$('ul > li')
350
- * await expect(elem).toHaveText(['Coffee', 'Tea', 'Milk'])
351
- * ```
352
- */
353
- toHaveText(
354
- text: string | RegExp | ExpectWebdriverIO.PartialMatcher | Array<string | RegExp | ExpectWebdriverIO.PartialMatcher>,
355
- options?: ExpectWebdriverIO.StringOptions
356
- ): R
357
-
358
- /**
359
- * `WebdriverIO.Element` -> `getHTML`
360
- * Element's html equals the html provided
361
- */
362
- toHaveHTML(html: string | RegExp | ExpectWebdriverIO.PartialMatcher | Array<string | RegExp>, options?: ExpectWebdriverIO.HTMLOptions): R
363
-
364
- /**
365
- * `WebdriverIO.Element` -> `getComputedLabel`
366
- * Element's computed label equals the computed label provided
367
- */
368
- toHaveComputedLabel(
369
- computedLabel: string | RegExp | ExpectWebdriverIO.PartialMatcher | Array<string | RegExp>,
370
- options?: ExpectWebdriverIO.StringOptions
371
- ): R
372
-
373
- /**
374
- * `WebdriverIO.Element` -> `getComputedRole`
375
- * Element's computed role equals the computed role provided
376
- */
377
- toHaveComputedRole(
378
- computedRole: string | RegExp | ExpectWebdriverIO.PartialMatcher | Array<string | RegExp>,
379
- options?: ExpectWebdriverIO.StringOptions
380
- ): R
381
-
382
- /**
383
- * `WebdriverIO.Element` -> `getSize('width')`
384
- * Element's width equals the width provided
385
- */
386
- toHaveWidth(width: number, options?: ExpectWebdriverIO.CommandOptions): R
387
-
388
- /**
389
- * `WebdriverIO.Element` -> `getSize('height')`
390
- * Element's height equals the height provided
391
- */
392
- toHaveHeight(height: number, options?: ExpectWebdriverIO.CommandOptions): R
393
-
394
- /**
395
- * `WebdriverIO.Element` -> `getSize()`
396
- * Element's size equals the size provided
397
- */
398
- toHaveHeight(size: { height: number; width: number }, options?: ExpectWebdriverIO.CommandOptions): R
399
-
400
- /**
401
- * `WebdriverIO.Element` -> `getAttribute("style")`
402
- */
403
- toHaveStyle(style: { [key: string]: string }, options?: ExpectWebdriverIO.StringOptions): R
404
-
405
- // ===== browser only =====
406
- /**
407
- * `WebdriverIO.Browser` -> `getUrl`
408
- */
409
- toHaveUrl(url: string | RegExp | ExpectWebdriverIO.PartialMatcher, options?: ExpectWebdriverIO.StringOptions): R
410
-
411
- /**
412
- * `WebdriverIO.Browser` -> `getTitle`
413
- */
414
- toHaveTitle(title: string | RegExp | ExpectWebdriverIO.PartialMatcher, options?: ExpectWebdriverIO.StringOptions): R
415
-
416
- /**
417
- * `WebdriverIO.Browser` -> `execute`
418
- */
419
- toHaveClipboardText(clipboardText: string | RegExp | ExpectWebdriverIO.PartialMatcher, options?: ExpectWebdriverIO.StringOptions): R
420
-
421
- // ===== $$ only =====
422
- /**
423
- * `WebdriverIO.ElementArray` -> `$$('...').length`
424
- * supports less / greater then or equals to be passed in options
425
- */
426
- toBeElementsArrayOfSize(
427
- size: number | ExpectWebdriverIO.NumberOptions,
428
- options?: ExpectWebdriverIO.NumberOptions
429
- ): R & Promise<WebdriverIO.ElementArray>
430
-
431
- // ==== network mock ====
432
- /**
433
- * Check that `WebdriverIO.Mock` was called
434
- */
435
- toBeRequested(options?: ExpectWebdriverIO.CommandOptions): R
436
- /**
437
- * Check that `WebdriverIO.Mock` was called N times
438
- */
439
- toBeRequestedTimes(
440
- times: number | ExpectWebdriverIO.NumberOptions,
441
- options?: ExpectWebdriverIO.NumberOptions
442
- ): R
443
- /**
444
- * Check that `WebdriverIO.Mock` was called with the specific parameters
445
- */
446
- toBeRequestedWith(requestedWith: RequestedWith, options?: ExpectWebdriverIO.CommandOptions): R
447
- /**
448
- * snapshot matcher
449
- * @param label optional snapshot label
450
- */
451
- toMatchSnapshot(label?: string): R
452
- /**
453
- * inline snapshot matcher
454
- * @param snapshot snapshot string (autogenerated if not specified)
455
- * @param label optional snapshot label
456
- */
457
- toMatchInlineSnapshot(snapshot?: string, label?: string): R
458
- }
459
-
460
705
  type RequestedWith = {
461
- url?: string | ExpectWebdriverIO.PartialMatcher | ((url: string) => boolean)
706
+ url?: string | ExpectWebdriverIO.PartialMatcher<string>| ((url: string) => boolean)
462
707
  method?: string | Array<string>
463
708
  statusCode?: number | Array<number>
464
709
  requestHeaders?:
465
710
  | Record<string, string>
466
- | ExpectWebdriverIO.PartialMatcher
711
+ | ExpectWebdriverIO.PartialMatcher<Record<string, string>>
467
712
  | ((headers: Record<string, string>) => boolean)
468
713
  responseHeaders?:
469
714
  | Record<string, string>
470
- | ExpectWebdriverIO.PartialMatcher
715
+ | ExpectWebdriverIO.PartialMatcher<Record<string, string>>
471
716
  | ((headers: Record<string, string>) => boolean)
472
717
  postData?:
473
718
  | string
474
719
  | ExpectWebdriverIO.JsonCompatible
475
- | ExpectWebdriverIO.PartialMatcher
476
- | ((r: string | undefined) => boolean)
720
+ | ExpectWebdriverIO.PartialMatcher<string | ExpectWebdriverIO.JsonCompatible>
721
+ | ((postData: string | undefined) => boolean)
477
722
  response?:
478
723
  | string
479
724
  | ExpectWebdriverIO.JsonCompatible
480
- | ExpectWebdriverIO.PartialMatcher
481
- | ((r: string) => boolean)
725
+ | ExpectWebdriverIO.PartialMatcher<string | ExpectWebdriverIO.JsonCompatible>
726
+ | ((response: unknown) => boolean)
482
727
  }
483
728
 
484
729
  type jsonPrimitive = string | number | boolean | null
@@ -486,66 +731,11 @@ declare namespace ExpectWebdriverIO {
486
731
  type jsonArray = Array<jsonPrimitive | jsonObject | jsonArray>
487
732
  type JsonCompatible = jsonObject | jsonArray
488
733
 
489
- interface PartialMatcher {
490
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
491
- sample?: any
492
- $$typeof: symbol
493
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
494
- asymmetricMatch(...args: any[]): boolean
495
- toString(): string
496
- }
497
-
498
734
  /**
499
- * expect function declaration, containing two generics:
500
- * - T: the type of the actual value, e.g. WebdriverIO.Browser or WebdriverIO.Element
501
- * - R: the type of the return value, e.g. Promise<void> or void
735
+ * Allow to partially matches value. Same as asymmetric matcher in jest.
736
+ * Some properties are omitted for the type check to work correctly.
502
737
  */
503
- interface Expect {
504
- <T = unknown, R extends void | Promise<void> = void | Promise<void>>(actual: T): Matchers<R, T>
505
-
506
- /**
507
- * Creates a soft assertion wrapper around standard expect
508
- * Soft assertions record failures but don't throw errors immediately
509
- * All failures are collected and reported at the end of the test
510
- */
511
- soft<T = unknown>(actual: T): Matchers<Promise<void>, T>
512
-
513
- /**
514
- * Get all current soft assertion failures
515
- */
516
- getSoftFailures(testId?: string): SoftFailure[]
517
-
518
- /**
519
- * Manually assert all soft failures (throws an error if any failures exist)
520
- */
521
- assertSoftFailures(testId?: string): void
522
-
523
- /**
524
- * Clear all current soft assertion failures
525
- */
526
- clearSoftFailures(testId?: string): void
527
-
528
- // Standard asymmetric matchers from Jest
529
- extend(map: Record<string, Function>): void
530
- anything(): PartialMatcher
531
- any(sample: unknown): PartialMatcher
532
- stringContaining(expected: string): PartialMatcher
533
- objectContaining(sample: Record<string, unknown>): PartialMatcher
534
- arrayContaining(sample: Array<unknown>): PartialMatcher
535
- stringMatching(expected: string | RegExp): PartialMatcher
536
- not: AsymmetricMatchers
537
- }
538
-
539
- interface AsymmetricMatchers {
540
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
541
- any(expectedObject: any): PartialMatcher
542
- anything(): PartialMatcher
543
- arrayContaining(sample: Array<unknown>): PartialMatcher
544
- objectContaining(sample: Record<string, unknown>): PartialMatcher
545
- stringContaining(expected: string): PartialMatcher
546
- stringMatching(expected: string | RegExp): PartialMatcher
547
- not: AsymmetricMatchers
548
- }
738
+ type PartialMatcher<T> = Omit<ExpectLibAsymmetricMatcher<T>, 'sample' | 'inverse' | '$$typeof'>
549
739
  }
550
740
 
551
741
  declare module 'expect-webdriverio' {