expect-webdriverio 4.15.0 → 4.15.2
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.
|
@@ -2,20 +2,21 @@ import { DEFAULT_OPTIONS } from '../../constants.js';
|
|
|
2
2
|
import { compareText, compareTextWithArray, enhanceError, executeCommand, waitUntil, wrapExpectedWithArray } from '../../utils.js';
|
|
3
3
|
async function condition(el, text, options) {
|
|
4
4
|
const actualTextArray = [];
|
|
5
|
-
|
|
5
|
+
const resultArray = [];
|
|
6
|
+
let checkAllValuesMatchCondition;
|
|
6
7
|
if (Array.isArray(el)) {
|
|
7
|
-
const
|
|
8
|
-
actualText = await
|
|
8
|
+
for (const element of el) {
|
|
9
|
+
const actualText = await element.getText();
|
|
9
10
|
actualTextArray.push(actualText);
|
|
10
|
-
|
|
11
|
+
const result = Array.isArray(text)
|
|
11
12
|
? compareTextWithArray(actualText, text, options).result
|
|
12
13
|
: compareText(actualText, text, options).result;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
checkAllValuesMatchCondition =
|
|
14
|
+
resultArray.push(result);
|
|
15
|
+
}
|
|
16
|
+
checkAllValuesMatchCondition = resultArray.every(result => result);
|
|
16
17
|
}
|
|
17
18
|
else {
|
|
18
|
-
actualText = await el.getText();
|
|
19
|
+
const actualText = await el.getText();
|
|
19
20
|
actualTextArray.push(actualText);
|
|
20
21
|
checkAllValuesMatchCondition = Array.isArray(text)
|
|
21
22
|
? compareTextWithArray(actualText, text, options).result
|
package/lib/utils.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import isEqual from 'lodash.isequal';
|
|
2
|
+
import expect from 'expect';
|
|
2
3
|
import { DEFAULT_OPTIONS } from './constants.js';
|
|
3
4
|
import { wrapExpectedWithArray } from './util/elementsUtil.js';
|
|
4
5
|
import { executeCommand } from './util/executeCommand.js';
|
|
@@ -10,6 +11,9 @@ const asymmetricMatcher = typeof Symbol === 'function' && Symbol.for
|
|
|
10
11
|
export function isAsymmeyricMatcher(expected) {
|
|
11
12
|
return typeof expected === 'object' && '$$typeof' in expected && expected.$$typeof === asymmetricMatcher && expected.asymmetricMatch;
|
|
12
13
|
}
|
|
14
|
+
function isStringContainingMatcher(expected) {
|
|
15
|
+
return isAsymmeyricMatcher(expected) && ['StringContaining', 'StringNotContaining'].includes(expected.toString());
|
|
16
|
+
}
|
|
13
17
|
const waitUntil = async (condition, isNot = false, { wait = DEFAULT_OPTIONS.wait, interval = DEFAULT_OPTIONS.interval } = {}) => {
|
|
14
18
|
if (wait === 0) {
|
|
15
19
|
return await condition();
|
|
@@ -95,6 +99,11 @@ export const compareText = (actual, expected, { ignoreCase = false, trim = true,
|
|
|
95
99
|
if (typeof expected === 'string') {
|
|
96
100
|
expected = expected.toLowerCase();
|
|
97
101
|
}
|
|
102
|
+
else if (isStringContainingMatcher(expected)) {
|
|
103
|
+
expected = (expected.toString() === 'StringContaining'
|
|
104
|
+
? expect.stringContaining(expected.sample?.toString().toLowerCase())
|
|
105
|
+
: expect.not.stringContaining(expected.sample?.toString().toLowerCase()));
|
|
106
|
+
}
|
|
98
107
|
}
|
|
99
108
|
if (isAsymmeyricMatcher(expected)) {
|
|
100
109
|
const result = expected.asymmetricMatch(actual);
|
|
@@ -154,12 +163,15 @@ export const compareTextWithArray = (actual, expectedArray, { ignoreCase = false
|
|
|
154
163
|
}
|
|
155
164
|
if (ignoreCase) {
|
|
156
165
|
actual = actual.toLowerCase();
|
|
157
|
-
expectedArray = expectedArray.map((item) => (item
|
|
166
|
+
expectedArray = expectedArray.map((item) => (typeof item !== 'string' ? item : item.toLowerCase()));
|
|
158
167
|
}
|
|
159
168
|
const textInArray = expectedArray.some((expected) => {
|
|
160
169
|
if (expected instanceof RegExp) {
|
|
161
170
|
return !!actual.match(expected);
|
|
162
171
|
}
|
|
172
|
+
if (isAsymmeyricMatcher(expected)) {
|
|
173
|
+
return expected.asymmetricMatch(actual);
|
|
174
|
+
}
|
|
163
175
|
if (containing) {
|
|
164
176
|
return actual.includes(expected);
|
|
165
177
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expect-webdriverio",
|
|
3
|
-
"version": "4.15.
|
|
3
|
+
"version": "4.15.2",
|
|
4
4
|
"author": "Mykola Grybyk <mykola.grybyk@gmail.com>",
|
|
5
5
|
"description": "WebdriverIO Assertion Library",
|
|
6
6
|
"license": "MIT",
|
|
@@ -61,14 +61,14 @@
|
|
|
61
61
|
"@types/debug": "^4.1.12",
|
|
62
62
|
"@types/jest": "^29.5.11",
|
|
63
63
|
"@types/lodash.isequal": "^4.5.8",
|
|
64
|
-
"@types/node": "^
|
|
64
|
+
"@types/node": "^22.0.0",
|
|
65
65
|
"@typescript-eslint/eslint-plugin": "^7.0.0",
|
|
66
66
|
"@typescript-eslint/parser": "^7.0.1",
|
|
67
67
|
"@vitest/coverage-v8": "^1.2.2",
|
|
68
|
-
"c8": "^
|
|
68
|
+
"c8": "^10.1.2",
|
|
69
69
|
"eslint": "^8.56.0",
|
|
70
70
|
"eslint-plugin-import": "^2.29.1",
|
|
71
|
-
"eslint-plugin-unicorn": "^
|
|
71
|
+
"eslint-plugin-unicorn": "^55.0.0",
|
|
72
72
|
"husky": "^9.0.7",
|
|
73
73
|
"npm-run-all2": "^6.1.2",
|
|
74
74
|
"release-it": "^17.0.3",
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"shelljs": "^0.8.5",
|
|
77
77
|
"typescript": "^5.3.3",
|
|
78
78
|
"vitest": "1.6.0",
|
|
79
|
-
"webdriverio": "8.
|
|
79
|
+
"webdriverio": "8.40.2"
|
|
80
80
|
},
|
|
81
81
|
"optionalDependencies": {
|
|
82
82
|
"@wdio/globals": "^8.29.3",
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"webdriverio": "^8.29.3"
|
|
85
85
|
},
|
|
86
86
|
"dependencies": {
|
|
87
|
-
"@vitest/snapshot": "^
|
|
87
|
+
"@vitest/snapshot": "^2.0.3",
|
|
88
88
|
"expect": "^29.7.0",
|
|
89
89
|
"jest-matcher-utils": "^29.7.0",
|
|
90
90
|
"lodash.isequal": "^4.5.0"
|