expect-webdriverio 4.4.0 → 4.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/lib/utils.js CHANGED
@@ -12,12 +12,12 @@ const waitUntil = async (condition, isNot = false, { wait = DEFAULT_OPTIONS.wait
12
12
  let error;
13
13
  const start = Date.now();
14
14
  while (true) {
15
- if ((Date.now() - start) > wait) {
15
+ if (Date.now() - start > wait) {
16
16
  throw new Error('timeout');
17
17
  }
18
18
  error = undefined;
19
19
  try {
20
- const result = isNot !== await condition();
20
+ const result = isNot !== (await condition());
21
21
  if (result) {
22
22
  break;
23
23
  }
@@ -50,7 +50,7 @@ async function executeCommandBe(received, command, options) {
50
50
  const message = enhanceErrorBe(el, pass, this, verb, expectation, options);
51
51
  return {
52
52
  pass,
53
- message: () => message
53
+ message: () => message,
54
54
  };
55
55
  }
56
56
  const compareNumbers = (actual, options = {}) => {
@@ -68,11 +68,11 @@ const compareNumbers = (actual, options = {}) => {
68
68
  }
69
69
  return false;
70
70
  };
71
- export const compareText = (actual, expected, { ignoreCase = false, trim = true, containing = false, atStart = false, atEnd = false, atIndex, replace }) => {
71
+ export const compareText = (actual, expected, { ignoreCase = false, trim = true, containing = false, atStart = false, atEnd = false, atIndex, replace, }) => {
72
72
  if (typeof actual !== 'string') {
73
73
  return {
74
74
  value: actual,
75
- result: false
75
+ result: false,
76
76
  };
77
77
  }
78
78
  if (trim) {
@@ -90,43 +90,43 @@ export const compareText = (actual, expected, { ignoreCase = false, trim = true,
90
90
  if (expected instanceof RegExp) {
91
91
  return {
92
92
  value: actual,
93
- result: !!actual.match(expected)
93
+ result: !!actual.match(expected),
94
94
  };
95
95
  }
96
96
  if (containing) {
97
97
  return {
98
98
  value: actual,
99
- result: actual.includes(expected)
99
+ result: actual.includes(expected),
100
100
  };
101
101
  }
102
102
  if (atStart) {
103
103
  return {
104
104
  value: actual,
105
- result: actual.startsWith(expected)
105
+ result: actual.startsWith(expected),
106
106
  };
107
107
  }
108
108
  if (atEnd) {
109
109
  return {
110
110
  value: actual,
111
- result: actual.endsWith(expected)
111
+ result: actual.endsWith(expected),
112
112
  };
113
113
  }
114
114
  if (atIndex) {
115
115
  return {
116
116
  value: actual,
117
- result: actual.substring(atIndex, actual.length).startsWith(expected)
117
+ result: actual.substring(atIndex, actual.length).startsWith(expected),
118
118
  };
119
119
  }
120
120
  return {
121
121
  value: actual,
122
- result: actual === expected
122
+ result: actual === expected,
123
123
  };
124
124
  };
125
- export const compareTextWithArray = (actual, expectedArray, { ignoreCase = false, trim = false, containing = false, atStart = false, atEnd = false, atIndex, replace }) => {
125
+ export const compareTextWithArray = (actual, expectedArray, { ignoreCase = false, trim = false, containing = false, atStart = false, atEnd = false, atIndex, replace, }) => {
126
126
  if (typeof actual !== 'string') {
127
127
  return {
128
128
  value: actual,
129
- result: false
129
+ result: false,
130
130
  };
131
131
  }
132
132
  if (trim) {
@@ -137,7 +137,7 @@ export const compareTextWithArray = (actual, expectedArray, { ignoreCase = false
137
137
  }
138
138
  if (ignoreCase) {
139
139
  actual = actual.toLowerCase();
140
- expectedArray = expectedArray.map(item => (item instanceof RegExp) ? item : item.toLowerCase());
140
+ expectedArray = expectedArray.map((item) => (item instanceof RegExp ? item : item.toLowerCase()));
141
141
  }
142
142
  const textInArray = expectedArray.some((expected) => {
143
143
  if (expected instanceof RegExp) {
@@ -159,19 +159,19 @@ export const compareTextWithArray = (actual, expectedArray, { ignoreCase = false
159
159
  });
160
160
  return {
161
161
  value: actual,
162
- result: textInArray
162
+ result: textInArray,
163
163
  };
164
164
  };
165
165
  export const compareObject = (actual, expected) => {
166
166
  if (typeof actual !== 'object' || Array.isArray(actual)) {
167
167
  return {
168
168
  value: actual,
169
- result: false
169
+ result: false,
170
170
  };
171
171
  }
172
172
  return {
173
173
  value: actual,
174
- result: isEqual(actual, expected)
174
+ result: isEqual(actual, expected),
175
175
  };
176
176
  };
177
177
  export const compareStyle = async (actualEl, style, { ignoreCase = true, trim = false }) => {
@@ -194,21 +194,21 @@ export const compareStyle = async (actualEl, style, { ignoreCase = true, trim =
194
194
  }
195
195
  return {
196
196
  value: actual,
197
- result
197
+ result,
198
198
  };
199
199
  };
200
- function aliasFn(fn, { verb, expectation } = {}, ...args) {
200
+ function aliasFn(fn, { verb, expectation, } = {}, ...args) {
201
201
  this.verb = verb;
202
202
  this.expectation = expectation;
203
203
  return fn.apply(this, args);
204
204
  }
205
- export { updateElementsArray, wrapExpectedWithArray, enhanceError, numberError, executeCommand, executeCommandBe, waitUntil, compareNumbers, aliasFn };
205
+ export { updateElementsArray, wrapExpectedWithArray, enhanceError, numberError, executeCommand, executeCommandBe, waitUntil, compareNumbers, aliasFn, };
206
206
  function replaceActual(replace, actual) {
207
- const hasMultipleReplacers = replace.every(r => Array.isArray(r));
207
+ const hasMultipleReplacers = replace.every((r) => Array.isArray(r));
208
208
  const replacers = hasMultipleReplacers
209
209
  ? replace
210
210
  : [replace];
211
- if (replacers.some(r => Array.isArray(r) && r.length !== 2)) {
211
+ if (replacers.some((r) => Array.isArray(r) && r.length !== 2)) {
212
212
  throw new Error('Replacers need to have a searchValue and a replaceValue');
213
213
  }
214
214
  for (const replacer of replacers) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expect-webdriverio",
3
- "version": "4.4.0",
3
+ "version": "4.4.1",
4
4
  "author": "Mykola Grybyk <mykola.grybyk@gmail.com>",
5
5
  "description": "WebdriverIO Assertion Library",
6
6
  "license": "MIT",
@@ -76,7 +76,7 @@
76
76
  "rimraf": "^5.0.1",
77
77
  "shelljs": "^0.8.5",
78
78
  "typescript": "^5.2.2",
79
- "vitest": "0.34.5",
79
+ "vitest": "0.34.6",
80
80
  "webdriverio": "^8.16.7"
81
81
  },
82
82
  "optionalDependencies": {
@@ -1,469 +1,450 @@
1
- type searchValue = string | RegExp
2
- type replaceValue = string | ((substring: string, ...args: any[]) => string)
3
- export type Replacer = [searchValue, replaceValue]
4
-
5
- declare global {
6
- namespace ExpectWebdriverIO {
7
- function expect<T = unknown, R extends void | Promise<void> = void | Promise<void>>(
8
- actual: T
9
- ): Matchers<R, T>
10
- function setOptions(options: DefaultOptions): void
11
- function getConfig(): any
12
- const matchers: Record<
13
- string,
14
- (
15
- actual: any,
16
- ...expected: any[]
17
- ) => Promise<{
18
- pass: boolean
19
- message(): string
20
- }>
21
- >
22
-
23
- interface DefaultOptions {
24
- /**
25
- * time in ms to wait for expectation to succeed. Default: 3000
26
- */
27
- wait?: number
28
-
29
- /**
30
- * interval between attempts. Default: 100
31
- */
32
- interval?: number
33
- }
34
-
35
- interface CommandOptions extends DefaultOptions {
36
- /**
37
- * user message to prepend before assertion error
38
- */
39
- message?: string
40
- }
41
-
42
- interface HTMLOptions extends StringOptions {
43
- /**
44
- * return the HTML with the selector tag included
45
- */
46
- includeSelectorTag?: boolean
47
- }
48
-
49
- interface StringOptions extends CommandOptions {
50
- /**
51
- * apply `toLowerCase` to both actual and expected values
52
- */
53
- ignoreCase?: boolean
54
-
55
- /**
56
- * apply `trim` to actual value
57
- */
58
- trim?: boolean
59
-
60
- /**
61
- * expect actual value to contain expected value.
62
- * Otherwise strict equal
63
- */
64
- containing?: boolean
65
-
66
- /**
67
- * expect actual value to start with the expected value
68
- * Otherwise strict equal
69
- */
70
- atStart?: boolean
71
-
72
- /**
73
- * expect actual value to end with the expected value
74
- * Otherwise strict equal
75
- */
76
- atEnd?: boolean
77
-
78
- /**
79
- * expect actual value to have the expected value at the given index (index starts at 0 not 1)
80
- * Otherwise strict equal
81
- */
82
- atIndex?: number
83
-
84
- /**
85
- * replace the actual value (example: strip newlines from the value) and expect it to match the expected value
86
- * Otherwise strict equal
87
- */
88
- replace?: Replacer | Replacer[]
89
-
90
- /**
91
- * might be helpful to force converting property value to string
92
- */
93
- asString?: boolean
94
- }
95
-
96
- interface NumberOptions extends CommandOptions {
97
- /**
98
- * equals
99
- */
100
- eq?: number
101
- /**
102
- * less than or equals
103
- */
104
- lte?: number
105
-
106
- /**
107
- * greater than or equals
108
- */
109
- gte?: number
110
- }
111
-
112
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
113
- interface Matchers<R, T> {
114
- // ===== $ or $$ =====
115
- /**
116
- * `WebdriverIO.Element` -> `isDisplayed`
117
- */
118
- toBeDisplayed(options?: ExpectWebdriverIO.CommandOptions): R
119
-
120
- /**
121
- * `WebdriverIO.Element` -> `isExisting`
122
- */
123
- toExist(options?: ExpectWebdriverIO.CommandOptions): R
124
- /**
125
- * `WebdriverIO.Element` -> `isExisting`
126
- */
127
- toBePresent(options?: ExpectWebdriverIO.CommandOptions): R
128
- /**
129
- * `WebdriverIO.Element` -> `isExisting`
130
- */
131
- toBeExisting(options?: ExpectWebdriverIO.CommandOptions): R
132
-
133
- /**
134
- * `WebdriverIO.Element` -> `getAttribute`
135
- */
136
- toHaveAttribute(
137
- attribute: string,
138
- value?: string | RegExp,
139
- options?: ExpectWebdriverIO.StringOptions
140
- ): R
141
- /**
142
- * `WebdriverIO.Element` -> `getAttribute`
143
- */
144
- toHaveAttr(
145
- attribute: string,
146
- value?: string | RegExp,
147
- options?: ExpectWebdriverIO.StringOptions
148
- ): R
149
-
150
- /**
151
- * `WebdriverIO.Element` -> `getAttribute`
152
- * Element's attribute includes the value.
153
- */
154
- toHaveAttributeContaining(
155
- attribute: string,
156
- contains: string | RegExp,
157
- options?: ExpectWebdriverIO.StringOptions
158
- ): R
159
- /**
160
- * `WebdriverIO.Element` -> `getAttribute`
161
- * Element's attribute includes the value.
162
- */
163
- toHaveAttrContaining(
164
- attribute: string,
165
- contains: string | RegExp,
166
- options?: ExpectWebdriverIO.StringOptions
167
- ): R
168
-
169
- /**
170
- * `WebdriverIO.Element` -> `getAttribute` class
171
- * @deprecated since v1.3.1 - use `toHaveElementClass` instead.
172
- */
173
- toHaveClass(className: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
174
-
175
- /**
176
- * `WebdriverIO.Element` -> `getAttribute` class
177
- */
178
- toHaveElementClass(className: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
179
-
180
- /**
181
- * `WebdriverIO.Element` -> `getAttribute` class
182
- * @deprecated since v1.3.1 - use `toHaveElementClassContaining` instead.
183
- * Element's class includes the className.
184
- */
185
- toHaveClassContaining(className: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
186
-
187
- /**
188
- * `WebdriverIO.Element` -> `getAttribute` class
189
- * Element's class includes the className.
190
- */
191
- toHaveElementClassContaining(
192
- className: string | RegExp,
193
- options?: ExpectWebdriverIO.StringOptions
194
- ): R
195
-
196
- /**
197
- * `WebdriverIO.Element` -> `getProperty`
198
- */
199
- toHaveElementProperty(
200
- property: string | RegExp,
201
- value?: any,
202
- options?: ExpectWebdriverIO.StringOptions
203
- ): R
204
-
205
- /**
206
- * `WebdriverIO.Element` -> `getProperty` value
207
- */
208
- toHaveValue(value: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
209
- /**
210
- * `WebdriverIO.Element` -> `getProperty` value
211
- * Element's value includes the value.
212
- */
213
- toHaveValueContaining(value: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
214
-
215
- /**
216
- * `WebdriverIO.Element` -> `isClickable`
217
- */
218
- toBeClickable(options?: ExpectWebdriverIO.StringOptions): R
219
-
220
- /**
221
- * `WebdriverIO.Element` -> `!isEnabled`
222
- */
223
- toBeDisabled(options?: ExpectWebdriverIO.StringOptions): R
224
-
225
- /**
226
- * `WebdriverIO.Element` -> `isDisplayedInViewport`
227
- */
228
- toBeDisplayedInViewport(options?: ExpectWebdriverIO.StringOptions): R
229
-
230
- /**
231
- * `WebdriverIO.Element` -> `isEnabled`
232
- */
233
- toBeEnabled(options?: ExpectWebdriverIO.StringOptions): R
234
-
235
- /**
236
- * `WebdriverIO.Element` -> `isFocused`
237
- */
238
- toBeFocused(options?: ExpectWebdriverIO.StringOptions): R
239
-
240
- /**
241
- * `WebdriverIO.Element` -> `isSelected`
242
- */
243
- toBeSelected(options?: ExpectWebdriverIO.StringOptions): R
244
-
245
- /**
246
- * `WebdriverIO.Element` -> `isSelected`
247
- */
248
- toBeChecked(options?: ExpectWebdriverIO.StringOptions): R
249
-
250
- /**
251
- * `WebdriverIO.Element` -> `$$('./*').length`
252
- * supports less / greater then or equals to be passed in options
253
- */
254
- toHaveChildren(
255
- size?: number | ExpectWebdriverIO.NumberOptions,
256
- options?: ExpectWebdriverIO.NumberOptions
257
- ): R
258
-
259
- /**
260
- * `WebdriverIO.Element` -> `getAttribute` href
261
- */
262
- toHaveHref(href: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
263
- /**
264
- * `WebdriverIO.Element` -> `getAttribute` href
265
- */
266
- toHaveLink(href: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
267
-
268
- /**
269
- * `WebdriverIO.Element` -> `getAttribute` href
270
- * Element's href includes the value provided
271
- */
272
- toHaveHrefContaining(href: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
273
- /**
274
- * `WebdriverIO.Element` -> `getAttribute` href
275
- * Element's href includes the value provided
276
- */
277
- toHaveLinkContaining(href: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
278
-
279
- /**
280
- * `WebdriverIO.Element` -> `getProperty` value
281
- */
282
- toHaveId(id: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
283
-
284
- /**
285
- * `WebdriverIO.Element` -> `getText`
286
- * Element's text equals the text provided
287
- */
288
- toHaveText(
289
- text: string | RegExp | Array<string | RegExp>,
290
- options?: ExpectWebdriverIO.StringOptions
291
- ): R
292
- /**
293
- * `WebdriverIO.Element` -> `getText`
294
- * Element's text includes the text provided
295
- */
296
- toHaveTextContaining(
297
- text: string | RegExp | Array<string | RegExp>,
298
- options?: ExpectWebdriverIO.StringOptions
299
- ): R
300
-
301
- /**
302
- * `WebdriverIO.Element` -> `getHTML`
303
- * Element's html equals the html provided
304
- */
305
- toHaveHTML(
306
- html: string | RegExp | Array<string | RegExp>,
307
- options?: ExpectWebdriverIO.HTMLOptions
308
- ): R
309
- /**
310
- * `WebdriverIO.Element` -> `getHTML`
311
- * Element's html includes the html provided
312
- */
313
- toHaveHTMLContaining(
314
- html: string | RegExp | Array<string | RegExp>,
315
- options?: ExpectWebdriverIO.HTMLOptions
316
- ): R
317
-
318
- /**
319
- * `WebdriverIO.Element` -> `getComputedLabel`
320
- * Element's computed label equals the computed label provided
321
- */
322
- toHaveComputedLabel(
323
- computedLabel: string | RegExp | Array<string | RegExp>,
324
- options?: ExpectWebdriverIO.StringOptions
325
- ): R
326
- /**
327
- * `WebdriverIO.Element` -> `getComputedLabel`
328
- * Element's computed label includes the computed label provided
329
- */
330
- toHaveComputedLabelContaining(
331
- computedLabel: string | RegExp | Array<string | RegExp>,
332
- options?: ExpectWebdriverIO.StringOptions
333
- ): R
334
-
335
- /**
336
- * `WebdriverIO.Element` -> `getComputedRole`
337
- * Element's computed role equals the computed role provided
338
- */
339
- toHaveComputedRole(
340
- computedRole: string | RegExp | Array<string | RegExp>,
341
- options?: ExpectWebdriverIO.StringOptions
342
- ): R
343
- /**
344
- * `WebdriverIO.Element` -> `getComputedRole`
345
- * Element's computed role includes the computed role provided
346
- */
347
- toHaveComputedRoleContaining(
348
- computedRole: string | RegExp | Array<string | RegExp>,
349
- options?: ExpectWebdriverIO.StringOptions
350
- ): R
351
-
352
- /**
353
- * `WebdriverIO.Element` -> `getSize('width')`
354
- * Element's width equals the width provided
355
- */
356
- toHaveWidth(width: number, options?: ExpectWebdriverIO.CommandOptions): R
357
-
358
- /**
359
- * `WebdriverIO.Element` -> `getSize('height')`
360
- * Element's height equals the height provided
361
- */
362
- toHaveHeight(height: number, options?: ExpectWebdriverIO.CommandOptions): R
363
-
364
- /**
365
- * `WebdriverIO.Element` -> `getSize()`
366
- * Element's size equals the size provided
367
- */
368
- toHaveHeight(
369
- size: { height: number; width: number },
370
- options?: ExpectWebdriverIO.CommandOptions
371
- ): R
372
-
373
- /**
374
- * `WebdriverIO.Element` -> `getAttribute("style")`
375
- */
376
- toHaveStyle(style: { [key: string]: string }, options?: ExpectWebdriverIO.StringOptions): R
377
-
378
- // ===== browser only =====
379
- /**
380
- * `WebdriverIO.Browser` -> `getUrl`
381
- */
382
- toHaveUrl(url: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
383
-
384
- // ===== browser only =====
385
- /**
386
- * `WebdriverIO.Browser` -> `getUrl`
387
- * Browser's url includes the provided text
388
- */
389
- toHaveUrlContaining(url: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
390
-
391
- /**
392
- * `WebdriverIO.Browser` -> `getTitle`
393
- */
394
- toHaveTitle(title: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
395
-
396
- // ===== browser only =====
397
- /**
398
- * `WebdriverIO.Browser` -> `getTitle`
399
- * Browser's title includes the provided text
400
- */
401
- toHaveTitleContaining(title: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
402
-
403
- // ===== $$ only =====
404
- /**
405
- * `WebdriverIO.ElementArray` -> `$$('...').length`
406
- * supports less / greater then or equals to be passed in options
407
- */
408
- toBeElementsArrayOfSize(
409
- size: number | ExpectWebdriverIO.NumberOptions,
410
- options?: ExpectWebdriverIO.NumberOptions
411
- ): R
412
-
413
- // ==== network mock ====
414
-
415
- /**
416
- * Check that `WebdriverIO.Mock` was called
417
- */
418
- toBeRequested(options?: ExpectWebdriverIO.CommandOptions): R
419
-
420
- /**
421
- * Check that `WebdriverIO.Mock` was called N times
422
- */
423
- toBeRequestedTimes(
424
- times: number | ExpectWebdriverIO.NumberOptions,
425
- options?: ExpectWebdriverIO.NumberOptions
426
- ): R
427
-
428
- /**
429
- * Check that `WebdriverIO.Mock` was called with the specific parameters
430
- */
431
- toBeRequestedWith(requestedWith: RequestedWith, options?: ExpectWebdriverIO.CommandOptions): R
432
- }
433
-
434
- type RequestedWith = {
435
- url?: string | ExpectWebdriverIO.PartialMatcher | ((url: string) => boolean)
436
- method?: string | Array<string>
437
- statusCode?: number | Array<number>
438
- requestHeaders?:
439
- | Record<string, string>
440
- | ExpectWebdriverIO.PartialMatcher
441
- | ((headers: Record<string, string>) => boolean)
442
- responseHeaders?:
443
- | Record<string, string>
444
- | ExpectWebdriverIO.PartialMatcher
445
- | ((headers: Record<string, string>) => boolean)
446
- postData?:
447
- | string
448
- | ExpectWebdriverIO.JsonCompatible
449
- | ExpectWebdriverIO.PartialMatcher
450
- | ((r: string | undefined) => boolean)
451
- response?:
452
- | string
453
- | ExpectWebdriverIO.JsonCompatible
454
- | ExpectWebdriverIO.PartialMatcher
455
- | ((r: string) => boolean)
456
- }
457
-
458
- type jsonPrimitive = string | number | boolean | null
459
- type jsonObject = { [x: string]: jsonPrimitive | jsonObject | jsonArray }
460
- type jsonArray = Array<jsonPrimitive | jsonObject | jsonArray>
461
- type JsonCompatible = jsonObject | jsonArray
462
-
463
- interface PartialMatcher {
464
- sample?: any
465
- asymmetricMatch?(...args: any[]): boolean
466
- }
1
+ declare namespace ExpectWebdriverIO {
2
+ function expect<T = unknown, R extends void | Promise<void> = void | Promise<void>>(
3
+ actual: T
4
+ ): Matchers<R, T>
5
+ function setOptions(options: DefaultOptions): void
6
+ function getConfig(): any
7
+ const matchers: Record<
8
+ string,
9
+ (
10
+ actual: any,
11
+ ...expected: any[]
12
+ ) => Promise<{
13
+ pass: boolean
14
+ message(): string
15
+ }>
16
+ >
17
+
18
+ interface DefaultOptions {
19
+ /**
20
+ * time in ms to wait for expectation to succeed. Default: 3000
21
+ */
22
+ wait?: number
23
+
24
+ /**
25
+ * interval between attempts. Default: 100
26
+ */
27
+ interval?: number
28
+ }
29
+
30
+ interface CommandOptions extends DefaultOptions {
31
+ /**
32
+ * user message to prepend before assertion error
33
+ */
34
+ message?: string
35
+ }
36
+
37
+ interface HTMLOptions extends StringOptions {
38
+ /**
39
+ * return the HTML with the selector tag included
40
+ */
41
+ includeSelectorTag?: boolean
42
+ }
43
+
44
+ interface StringOptions extends CommandOptions {
45
+ /**
46
+ * apply `toLowerCase` to both actual and expected values
47
+ */
48
+ ignoreCase?: boolean
49
+
50
+ /**
51
+ * apply `trim` to actual value
52
+ */
53
+ trim?: boolean
54
+
55
+ /**
56
+ * expect actual value to contain expected value.
57
+ * Otherwise strict equal
58
+ */
59
+ containing?: boolean
60
+
61
+ /**
62
+ * expect actual value to start with the expected value
63
+ * Otherwise strict equal
64
+ */
65
+ atStart?: boolean
66
+
67
+ /**
68
+ * expect actual value to end with the expected value
69
+ * Otherwise strict equal
70
+ */
71
+ atEnd?: boolean
72
+
73
+ /**
74
+ * expect actual value to have the expected value at the given index (index starts at 0 not 1)
75
+ * Otherwise strict equal
76
+ */
77
+ atIndex?: number
78
+
79
+ /**
80
+ * replace the actual value (example: strip newlines from the value) and expect it to match the expected value
81
+ * Otherwise strict equal
82
+ */
83
+ replace?: [string | RegExp, string | Function] | Array<[string | RegExp, string | Function]>
84
+
85
+ /**
86
+ * might be helpful to force converting property value to string
87
+ */
88
+ asString?: boolean
89
+ }
90
+
91
+ interface NumberOptions extends CommandOptions {
92
+ /**
93
+ * equals
94
+ */
95
+ eq?: number
96
+ /**
97
+ * less than or equals
98
+ */
99
+ lte?: number
100
+
101
+ /**
102
+ * greater than or equals
103
+ */
104
+ gte?: number
105
+ }
106
+
107
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
108
+ interface Matchers<R, T> {
109
+ // ===== $ or $$ =====
110
+ /**
111
+ * `WebdriverIO.Element` -> `isDisplayed`
112
+ */
113
+ toBeDisplayed(options?: ExpectWebdriverIO.CommandOptions): R
114
+
115
+ /**
116
+ * `WebdriverIO.Element` -> `isExisting`
117
+ */
118
+ toExist(options?: ExpectWebdriverIO.CommandOptions): R
119
+ /**
120
+ * `WebdriverIO.Element` -> `isExisting`
121
+ */
122
+ toBePresent(options?: ExpectWebdriverIO.CommandOptions): R
123
+ /**
124
+ * `WebdriverIO.Element` -> `isExisting`
125
+ */
126
+ toBeExisting(options?: ExpectWebdriverIO.CommandOptions): R
127
+
128
+ /**
129
+ * `WebdriverIO.Element` -> `getAttribute`
130
+ */
131
+ toHaveAttribute(
132
+ attribute: string,
133
+ value?: string | RegExp,
134
+ options?: ExpectWebdriverIO.StringOptions
135
+ ): R
136
+ /**
137
+ * `WebdriverIO.Element` -> `getAttribute`
138
+ */
139
+ toHaveAttr(attribute: string, value?: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
140
+
141
+ /**
142
+ * `WebdriverIO.Element` -> `getAttribute`
143
+ * Element's attribute includes the value.
144
+ */
145
+ toHaveAttributeContaining(
146
+ attribute: string,
147
+ contains: string | RegExp,
148
+ options?: ExpectWebdriverIO.StringOptions
149
+ ): R
150
+ /**
151
+ * `WebdriverIO.Element` -> `getAttribute`
152
+ * Element's attribute includes the value.
153
+ */
154
+ toHaveAttrContaining(
155
+ attribute: string,
156
+ contains: string | RegExp,
157
+ options?: ExpectWebdriverIO.StringOptions
158
+ ): R
159
+
160
+ /**
161
+ * `WebdriverIO.Element` -> `getAttribute` class
162
+ * @deprecated since v1.3.1 - use `toHaveElementClass` instead.
163
+ */
164
+ toHaveClass(className: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
165
+
166
+ /**
167
+ * `WebdriverIO.Element` -> `getAttribute` class
168
+ */
169
+ toHaveElementClass(className: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
170
+
171
+ /**
172
+ * `WebdriverIO.Element` -> `getAttribute` class
173
+ * @deprecated since v1.3.1 - use `toHaveElementClassContaining` instead.
174
+ * Element's class includes the className.
175
+ */
176
+ toHaveClassContaining(className: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
177
+
178
+ /**
179
+ * `WebdriverIO.Element` -> `getAttribute` class
180
+ * Element's class includes the className.
181
+ */
182
+ toHaveElementClassContaining(className: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
183
+
184
+ /**
185
+ * `WebdriverIO.Element` -> `getProperty`
186
+ */
187
+ toHaveElementProperty(
188
+ property: string | RegExp,
189
+ value?: any,
190
+ options?: ExpectWebdriverIO.StringOptions
191
+ ): R
192
+
193
+ /**
194
+ * `WebdriverIO.Element` -> `getProperty` value
195
+ */
196
+ toHaveValue(value: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
197
+ /**
198
+ * `WebdriverIO.Element` -> `getProperty` value
199
+ * Element's value includes the value.
200
+ */
201
+ toHaveValueContaining(value: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
202
+
203
+ /**
204
+ * `WebdriverIO.Element` -> `isClickable`
205
+ */
206
+ toBeClickable(options?: ExpectWebdriverIO.StringOptions): R
207
+
208
+ /**
209
+ * `WebdriverIO.Element` -> `!isEnabled`
210
+ */
211
+ toBeDisabled(options?: ExpectWebdriverIO.StringOptions): R
212
+
213
+ /**
214
+ * `WebdriverIO.Element` -> `isDisplayedInViewport`
215
+ */
216
+ toBeDisplayedInViewport(options?: ExpectWebdriverIO.StringOptions): R
217
+
218
+ /**
219
+ * `WebdriverIO.Element` -> `isEnabled`
220
+ */
221
+ toBeEnabled(options?: ExpectWebdriverIO.StringOptions): R
222
+
223
+ /**
224
+ * `WebdriverIO.Element` -> `isFocused`
225
+ */
226
+ toBeFocused(options?: ExpectWebdriverIO.StringOptions): R
227
+
228
+ /**
229
+ * `WebdriverIO.Element` -> `isSelected`
230
+ */
231
+ toBeSelected(options?: ExpectWebdriverIO.StringOptions): R
232
+
233
+ /**
234
+ * `WebdriverIO.Element` -> `isSelected`
235
+ */
236
+ toBeChecked(options?: ExpectWebdriverIO.StringOptions): R
237
+
238
+ /**
239
+ * `WebdriverIO.Element` -> `$$('./*').length`
240
+ * supports less / greater then or equals to be passed in options
241
+ */
242
+ toHaveChildren(
243
+ size?: number | ExpectWebdriverIO.NumberOptions,
244
+ options?: ExpectWebdriverIO.NumberOptions
245
+ ): R
246
+
247
+ /**
248
+ * `WebdriverIO.Element` -> `getAttribute` href
249
+ */
250
+ toHaveHref(href: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
251
+ /**
252
+ * `WebdriverIO.Element` -> `getAttribute` href
253
+ */
254
+ toHaveLink(href: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
255
+
256
+ /**
257
+ * `WebdriverIO.Element` -> `getAttribute` href
258
+ * Element's href includes the value provided
259
+ */
260
+ toHaveHrefContaining(href: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
261
+ /**
262
+ * `WebdriverIO.Element` -> `getAttribute` href
263
+ * Element's href includes the value provided
264
+ */
265
+ toHaveLinkContaining(href: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
266
+
267
+ /**
268
+ * `WebdriverIO.Element` -> `getProperty` value
269
+ */
270
+ toHaveId(id: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
271
+
272
+ /**
273
+ * `WebdriverIO.Element` -> `getText`
274
+ * Element's text equals the text provided
275
+ */
276
+ toHaveText(
277
+ text: string | RegExp | Array<string | RegExp>,
278
+ options?: ExpectWebdriverIO.StringOptions
279
+ ): R
280
+ /**
281
+ * `WebdriverIO.Element` -> `getText`
282
+ * Element's text includes the text provided
283
+ */
284
+ toHaveTextContaining(
285
+ text: string | RegExp | Array<string | RegExp>,
286
+ options?: ExpectWebdriverIO.StringOptions
287
+ ): R
288
+
289
+ /**
290
+ * `WebdriverIO.Element` -> `getHTML`
291
+ * Element's html equals the html provided
292
+ */
293
+ toHaveHTML(html: string | RegExp | Array<string | RegExp>, options?: ExpectWebdriverIO.HTMLOptions): R
294
+ /**
295
+ * `WebdriverIO.Element` -> `getHTML`
296
+ * Element's html includes the html provided
297
+ */
298
+ toHaveHTMLContaining(
299
+ html: string | RegExp | Array<string | RegExp>,
300
+ options?: ExpectWebdriverIO.HTMLOptions
301
+ ): R
302
+
303
+ /**
304
+ * `WebdriverIO.Element` -> `getComputedLabel`
305
+ * Element's computed label equals the computed label provided
306
+ */
307
+ toHaveComputedLabel(
308
+ computedLabel: string | RegExp | Array<string | RegExp>,
309
+ options?: ExpectWebdriverIO.StringOptions
310
+ ): R
311
+ /**
312
+ * `WebdriverIO.Element` -> `getComputedLabel`
313
+ * Element's computed label includes the computed label provided
314
+ */
315
+ toHaveComputedLabelContaining(
316
+ computedLabel: string | RegExp | Array<string | RegExp>,
317
+ options?: ExpectWebdriverIO.StringOptions
318
+ ): R
319
+
320
+ /**
321
+ * `WebdriverIO.Element` -> `getComputedRole`
322
+ * Element's computed role equals the computed role provided
323
+ */
324
+ toHaveComputedRole(
325
+ computedRole: string | RegExp | Array<string | RegExp>,
326
+ options?: ExpectWebdriverIO.StringOptions
327
+ ): R
328
+ /**
329
+ * `WebdriverIO.Element` -> `getComputedRole`
330
+ * Element's computed role includes the computed role provided
331
+ */
332
+ toHaveComputedRoleContaining(
333
+ computedRole: string | RegExp | Array<string | RegExp>,
334
+ options?: ExpectWebdriverIO.StringOptions
335
+ ): R
336
+
337
+ /**
338
+ * `WebdriverIO.Element` -> `getSize('width')`
339
+ * Element's width equals the width provided
340
+ */
341
+ toHaveWidth(width: number, options?: ExpectWebdriverIO.CommandOptions): R
342
+
343
+ /**
344
+ * `WebdriverIO.Element` -> `getSize('height')`
345
+ * Element's height equals the height provided
346
+ */
347
+ toHaveHeight(height: number, options?: ExpectWebdriverIO.CommandOptions): R
348
+
349
+ /**
350
+ * `WebdriverIO.Element` -> `getSize()`
351
+ * Element's size equals the size provided
352
+ */
353
+ toHaveHeight(size: { height: number; width: number }, options?: ExpectWebdriverIO.CommandOptions): R
354
+
355
+ /**
356
+ * `WebdriverIO.Element` -> `getAttribute("style")`
357
+ */
358
+ toHaveStyle(style: { [key: string]: string }, options?: ExpectWebdriverIO.StringOptions): R
359
+
360
+ // ===== browser only =====
361
+ /**
362
+ * `WebdriverIO.Browser` -> `getUrl`
363
+ */
364
+ toHaveUrl(url: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
365
+
366
+ // ===== browser only =====
367
+ /**
368
+ * `WebdriverIO.Browser` -> `getUrl`
369
+ * Browser's url includes the provided text
370
+ */
371
+ toHaveUrlContaining(url: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
372
+
373
+ /**
374
+ * `WebdriverIO.Browser` -> `getTitle`
375
+ */
376
+ toHaveTitle(title: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
377
+
378
+ // ===== browser only =====
379
+ /**
380
+ * `WebdriverIO.Browser` -> `getTitle`
381
+ * Browser's title includes the provided text
382
+ */
383
+ toHaveTitleContaining(title: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
384
+
385
+ // ===== $$ only =====
386
+ /**
387
+ * `WebdriverIO.ElementArray` -> `$$('...').length`
388
+ * supports less / greater then or equals to be passed in options
389
+ */
390
+ toBeElementsArrayOfSize(
391
+ size: number | ExpectWebdriverIO.NumberOptions,
392
+ options?: ExpectWebdriverIO.NumberOptions
393
+ ): R
394
+
395
+ // ==== network mock ====
396
+
397
+ /**
398
+ * Check that `WebdriverIO.Mock` was called
399
+ */
400
+ toBeRequested(options?: ExpectWebdriverIO.CommandOptions): R
401
+
402
+ /**
403
+ * Check that `WebdriverIO.Mock` was called N times
404
+ */
405
+ toBeRequestedTimes(
406
+ times: number | ExpectWebdriverIO.NumberOptions,
407
+ options?: ExpectWebdriverIO.NumberOptions
408
+ ): R
409
+
410
+ /**
411
+ * Check that `WebdriverIO.Mock` was called with the specific parameters
412
+ */
413
+ toBeRequestedWith(requestedWith: RequestedWith, options?: ExpectWebdriverIO.CommandOptions): R
414
+ }
415
+
416
+ type RequestedWith = {
417
+ url?: string | ExpectWebdriverIO.PartialMatcher | ((url: string) => boolean)
418
+ method?: string | Array<string>
419
+ statusCode?: number | Array<number>
420
+ requestHeaders?:
421
+ | Record<string, string>
422
+ | ExpectWebdriverIO.PartialMatcher
423
+ | ((headers: Record<string, string>) => boolean)
424
+ responseHeaders?:
425
+ | Record<string, string>
426
+ | ExpectWebdriverIO.PartialMatcher
427
+ | ((headers: Record<string, string>) => boolean)
428
+ postData?:
429
+ | string
430
+ | ExpectWebdriverIO.JsonCompatible
431
+ | ExpectWebdriverIO.PartialMatcher
432
+ | ((r: string | undefined) => boolean)
433
+ response?:
434
+ | string
435
+ | ExpectWebdriverIO.JsonCompatible
436
+ | ExpectWebdriverIO.PartialMatcher
437
+ | ((r: string) => boolean)
438
+ }
439
+
440
+ type jsonPrimitive = string | number | boolean | null
441
+ type jsonObject = { [x: string]: jsonPrimitive | jsonObject | jsonArray }
442
+ type jsonArray = Array<jsonPrimitive | jsonObject | jsonArray>
443
+ type JsonCompatible = jsonObject | jsonArray
444
+
445
+ interface PartialMatcher {
446
+ sample?: any
447
+ asymmetricMatch?(...args: any[]): boolean
467
448
  }
468
449
  }
469
450