expect-webdriverio 3.2.0 → 3.3.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.
@@ -14,18 +14,17 @@ async function condition(el, attribute, value, options) {
14
14
  }
15
15
  if (ignoreCase) {
16
16
  attr = attr.toLowerCase();
17
- value = value.toLowerCase();
18
- }
19
- if (containing) {
20
- return {
21
- result: attr.includes(value),
22
- value: attr
23
- };
17
+ if (!(value instanceof RegExp)) {
18
+ value = value.toLowerCase();
19
+ }
24
20
  }
25
21
  const classes = attr.split(' ');
22
+ const valueInClasses = classes.some((t) => {
23
+ return value instanceof RegExp ? !!t.match(value) : containing ? t.includes(value) : t === value;
24
+ });
26
25
  return {
27
- result: classes.includes(value),
28
- value: attr
26
+ value: attr,
27
+ result: valueInClasses
29
28
  };
30
29
  }
31
30
  function toHaveElementClassFn(received, className, options = {}) {
@@ -12,7 +12,7 @@ async function condition(el, property, value, options = {}) {
12
12
  if (value === null) {
13
13
  return { result: true, value: prop };
14
14
  }
15
- if (typeof value !== 'string' || (typeof prop !== 'string' && !asString)) {
15
+ if (!(value instanceof RegExp) && (typeof value !== 'string' || (typeof prop !== 'string' && !asString))) {
16
16
  return { result: prop === value, value: prop };
17
17
  }
18
18
  prop = prop.toString();
package/lib/utils.js CHANGED
@@ -87,7 +87,15 @@ const compareText = (actual, expected, { ignoreCase = false, trim = true, contai
87
87
  }
88
88
  if (ignoreCase) {
89
89
  actual = actual.toLowerCase();
90
- expected = expected.toLowerCase();
90
+ if (!(expected instanceof RegExp)) {
91
+ expected = expected.toLowerCase();
92
+ }
93
+ }
94
+ if (expected instanceof RegExp) {
95
+ return {
96
+ value: actual,
97
+ result: !!actual.match(expected)
98
+ };
91
99
  }
92
100
  if (containing) {
93
101
  return {
@@ -113,18 +121,14 @@ const compareTextWithArray = (actual, expectedArray, { ignoreCase = false, trim
113
121
  }
114
122
  if (ignoreCase) {
115
123
  actual = actual.toLowerCase();
116
- expectedArray = expectedArray.map(item => item.toLowerCase());
117
- }
118
- if (containing) {
119
- const textInArray = expectedArray.some((t) => actual.includes(t));
120
- return {
121
- value: actual,
122
- result: textInArray
123
- };
124
+ expectedArray = expectedArray.map(item => (item instanceof RegExp) ? item : item.toLowerCase());
124
125
  }
126
+ const textInArray = expectedArray.some((expected) => {
127
+ return expected instanceof RegExp ? !!actual.match(expected) : containing ? actual.includes(expected) : actual === expected;
128
+ });
125
129
  return {
126
130
  value: actual,
127
- result: expectedArray.includes(actual)
131
+ result: textInArray
128
132
  };
129
133
  };
130
134
  exports.compareTextWithArray = compareTextWithArray;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expect-webdriverio",
3
- "version": "3.2.0",
3
+ "version": "3.3.1",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "homepage": "https://github.com/webdriverio/expect-webdriverio#readme",
44
44
  "devDependencies": {
45
- "@types/jasmine": "^3.10.1",
45
+ "@types/jasmine": "^4.0.0",
46
46
  "@types/jest": "^27.0.2",
47
47
  "@types/node": "^15.14.0",
48
48
  "@typescript-eslint/eslint-plugin": "^5.1.0",
@@ -83,11 +83,11 @@ declare namespace ExpectWebdriverIO {
83
83
  /**
84
84
  * `WebdriverIO.Element` -> `getAttribute`
85
85
  */
86
- toHaveAttribute(attribute: string, value?: string, options?: ExpectWebdriverIO.StringOptions): R
86
+ toHaveAttribute(attribute: string, value?: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
87
87
  /**
88
88
  * `WebdriverIO.Element` -> `getAttribute`
89
89
  */
90
- toHaveAttr(attribute: string, value?: string, options?: ExpectWebdriverIO.StringOptions): R
90
+ toHaveAttr(attribute: string, value?: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
91
91
 
92
92
  /**
93
93
  * `WebdriverIO.Element` -> `getAttribute`
@@ -95,7 +95,7 @@ declare namespace ExpectWebdriverIO {
95
95
  */
96
96
  toHaveAttributeContaining(
97
97
  attribute: string,
98
- contains: string,
98
+ contains: string | RegExp,
99
99
  options?: ExpectWebdriverIO.StringOptions
100
100
  ): R
101
101
  /**
@@ -104,7 +104,7 @@ declare namespace ExpectWebdriverIO {
104
104
  */
105
105
  toHaveAttrContaining(
106
106
  attribute: string,
107
- contains: string,
107
+ contains: string | RegExp,
108
108
  options?: ExpectWebdriverIO.StringOptions
109
109
  ): R
110
110
 
@@ -112,40 +112,40 @@ declare namespace ExpectWebdriverIO {
112
112
  * `WebdriverIO.Element` -> `getAttribute` class
113
113
  * @deprecated since v1.3.1 - use `toHaveElementClass` instead.
114
114
  */
115
- toHaveClass(className: string, options?: ExpectWebdriverIO.StringOptions): R
115
+ toHaveClass(className: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
116
116
 
117
117
  /**
118
118
  * `WebdriverIO.Element` -> `getAttribute` class
119
119
  */
120
- toHaveElementClass(className: string, options?: ExpectWebdriverIO.StringOptions): R
120
+ toHaveElementClass(className: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
121
121
 
122
122
  /**
123
123
  * `WebdriverIO.Element` -> `getAttribute` class
124
124
  * @deprecated since v1.3.1 - use `toHaveElementClassContaining` instead.
125
125
  * Element's class includes the className.
126
126
  */
127
- toHaveClassContaining(className: string, options?: ExpectWebdriverIO.StringOptions): R
127
+ toHaveClassContaining(className: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
128
128
 
129
129
  /**
130
130
  * `WebdriverIO.Element` -> `getAttribute` class
131
131
  * Element's class includes the className.
132
132
  */
133
- toHaveElementClassContaining(className: string, options?: ExpectWebdriverIO.StringOptions): R
133
+ toHaveElementClassContaining(className: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
134
134
 
135
135
  /**
136
136
  * `WebdriverIO.Element` -> `getProperty`
137
137
  */
138
- toHaveElementProperty(property: string, value?: any, options?: ExpectWebdriverIO.StringOptions): R
138
+ toHaveElementProperty(property: string | RegExp, value?: any, options?: ExpectWebdriverIO.StringOptions): R
139
139
 
140
140
  /**
141
141
  * `WebdriverIO.Element` -> `getProperty` value
142
142
  */
143
- toHaveValue(value: string, options?: ExpectWebdriverIO.StringOptions): R
143
+ toHaveValue(value: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
144
144
  /**
145
145
  * `WebdriverIO.Element` -> `getProperty` value
146
146
  * Element's value includes the value.
147
147
  */
148
- toHaveValueContaining(value: string, options?: ExpectWebdriverIO.StringOptions): R
148
+ toHaveValueContaining(value: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
149
149
 
150
150
  /**
151
151
  * `WebdriverIO.Element` -> `isClickable`
@@ -194,37 +194,37 @@ declare namespace ExpectWebdriverIO {
194
194
  /**
195
195
  * `WebdriverIO.Element` -> `getAttribute` href
196
196
  */
197
- toHaveHref(href: string, options?: ExpectWebdriverIO.StringOptions): R
197
+ toHaveHref(href: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
198
198
  /**
199
199
  * `WebdriverIO.Element` -> `getAttribute` href
200
200
  */
201
- toHaveLink(href: string, options?: ExpectWebdriverIO.StringOptions): R
201
+ toHaveLink(href: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
202
202
 
203
203
  /**
204
204
  * `WebdriverIO.Element` -> `getAttribute` href
205
205
  * Element's href includes the value provided
206
206
  */
207
- toHaveHrefContaining(href: string, options?: ExpectWebdriverIO.StringOptions): R
207
+ toHaveHrefContaining(href: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
208
208
  /**
209
209
  * `WebdriverIO.Element` -> `getAttribute` href
210
210
  * Element's href includes the value provided
211
211
  */
212
- toHaveLinkContaining(href: string, options?: ExpectWebdriverIO.StringOptions): R
212
+ toHaveLinkContaining(href: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
213
213
 
214
214
  /**
215
215
  * `WebdriverIO.Element` -> `getProperty` value
216
216
  */
217
- toHaveId(id: string, options?: ExpectWebdriverIO.StringOptions): R
217
+ toHaveId(id: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
218
218
 
219
219
  /**
220
220
  * `WebdriverIO.Element` -> `getText`
221
221
  */
222
- toHaveText(text: string | string[], options?: ExpectWebdriverIO.StringOptions): R
222
+ toHaveText(text: string | RegExp | Array<string | RegExp>, options?: ExpectWebdriverIO.StringOptions): R
223
223
  /**
224
224
  * `WebdriverIO.Element` -> `getText`
225
225
  * Element's text includes the text provided
226
226
  */
227
- toHaveTextContaining(text: string | string[], options?: ExpectWebdriverIO.StringOptions): R
227
+ toHaveTextContaining(text: string | RegExp | Array<string | RegExp>, options?: ExpectWebdriverIO.StringOptions): R
228
228
 
229
229
  /**
230
230
  * `WebdriverIO.Element` -> `getAttribute("style")`
@@ -235,26 +235,26 @@ declare namespace ExpectWebdriverIO {
235
235
  /**
236
236
  * `WebdriverIO.Browser` -> `getUrl`
237
237
  */
238
- toHaveUrl(url: string, options?: ExpectWebdriverIO.StringOptions): R
238
+ toHaveUrl(url: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
239
239
 
240
240
  // ===== browser only =====
241
241
  /**
242
242
  * `WebdriverIO.Browser` -> `getUrl`
243
243
  * Browser's url includes the provided text
244
244
  */
245
- toHaveUrlContaining(url: string, options?: ExpectWebdriverIO.StringOptions): R
245
+ toHaveUrlContaining(url: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
246
246
 
247
247
  /**
248
248
  * `WebdriverIO.Browser` -> `getTitle`
249
249
  */
250
- toHaveTitle(title: string, options?: ExpectWebdriverIO.StringOptions): R
250
+ toHaveTitle(title: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
251
251
 
252
252
  // ===== browser only =====
253
253
  /**
254
254
  * `WebdriverIO.Browser` -> `getTitle`
255
255
  * Browser's title includes the provided text
256
256
  */
257
- toHaveTitleContaining(title: string, options?: ExpectWebdriverIO.StringOptions): R
257
+ toHaveTitleContaining(title: string | RegExp, options?: ExpectWebdriverIO.StringOptions): R
258
258
 
259
259
  // ===== $$ only =====
260
260
  /**