expect-webdriverio 5.0.0-alpha.2 → 5.0.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/matchers/element/toBeDisplayedInViewport.js +1 -1
- package/lib/matchers/element/toHaveAttribute.js +1 -1
- package/lib/matchers/element/toHaveChildren.js +1 -1
- package/lib/matchers/element/toHaveClass.js +1 -1
- package/lib/matchers/element/toHaveComputedLabel.js +1 -1
- package/lib/matchers/element/toHaveComputedRole.js +1 -1
- package/lib/matchers/element/toHaveElementProperty.js +1 -1
- package/lib/matchers/element/toHaveHTML.js +2 -2
- package/lib/matchers/element/toHaveHeight.js +1 -1
- package/lib/matchers/element/toHaveSize.js +1 -1
- package/lib/matchers/element/toHaveStyle.js +1 -1
- package/lib/matchers/element/toHaveText.js +2 -2
- package/lib/matchers/element/toHaveWidth.js +1 -1
- package/lib/utils.js +25 -3
- package/package.json +14 -14
- package/types/expect-webdriverio.d.ts +1 -0
|
@@ -6,7 +6,7 @@ export async function toBeDisplayedInViewport(received, options = DEFAULT_OPTION
|
|
|
6
6
|
matcherName: 'toBeDisplayedInViewport',
|
|
7
7
|
options,
|
|
8
8
|
});
|
|
9
|
-
const result = await executeCommandBe.call(this, received, el => el?.
|
|
9
|
+
const result = await executeCommandBe.call(this, received, el => el?.isDisplayed({ withinViewport: true }), options);
|
|
10
10
|
await options.afterAssertion?.({
|
|
11
11
|
matcherName: 'toBeDisplayedInViewport',
|
|
12
12
|
options,
|
|
@@ -19,7 +19,7 @@ async function conditionAttrAndValue(el, attribute, value, options) {
|
|
|
19
19
|
export async function toHaveAttributeAndValue(received, attribute, value, options = DEFAULT_OPTIONS) {
|
|
20
20
|
const isNot = this.isNot;
|
|
21
21
|
const { expectation = 'attribute', verb = 'have' } = this;
|
|
22
|
-
let el = await received
|
|
22
|
+
let el = await received?.getElement();
|
|
23
23
|
let attr;
|
|
24
24
|
const pass = await waitUntil(async () => {
|
|
25
25
|
const result = await executeCommand.call(this, el, conditionAttrAndValue, options, [attribute, value, options]);
|
|
@@ -26,7 +26,7 @@ export async function toHaveChildren(received, expectedValue, options = DEFAULT_
|
|
|
26
26
|
const numberOptions = typeof expectedValue === 'number'
|
|
27
27
|
? { eq: expectedValue }
|
|
28
28
|
: expectedValue || {};
|
|
29
|
-
let el = await received
|
|
29
|
+
let el = await received?.getElement();
|
|
30
30
|
let children;
|
|
31
31
|
const pass = await waitUntil(async () => {
|
|
32
32
|
const result = await executeCommand.call(this, el, condition, numberOptions, [numberOptions]);
|
|
@@ -32,7 +32,7 @@ export async function toHaveElementClass(received, expectedValue, options = DEFA
|
|
|
32
32
|
options,
|
|
33
33
|
});
|
|
34
34
|
const attribute = 'class';
|
|
35
|
-
let el = await received
|
|
35
|
+
let el = await received?.getElement();
|
|
36
36
|
let attr;
|
|
37
37
|
const pass = await waitUntil(async () => {
|
|
38
38
|
const result = await executeCommand.call(this, el, condition, options, [attribute, expectedValue, options]);
|
|
@@ -15,7 +15,7 @@ export async function toHaveComputedLabel(received, expectedValue, options = DEF
|
|
|
15
15
|
expectedValue,
|
|
16
16
|
options,
|
|
17
17
|
});
|
|
18
|
-
let el = await received
|
|
18
|
+
let el = await received?.getElement();
|
|
19
19
|
let actualLabel;
|
|
20
20
|
const pass = await waitUntil(async () => {
|
|
21
21
|
const result = await executeCommand.call(this, el, condition, options, [expectedValue, options]);
|
|
@@ -15,7 +15,7 @@ export async function toHaveComputedRole(received, expectedValue, options = DEFA
|
|
|
15
15
|
expectedValue,
|
|
16
16
|
options,
|
|
17
17
|
});
|
|
18
|
-
let el = await received
|
|
18
|
+
let el = await received?.getElement();
|
|
19
19
|
let actualRole;
|
|
20
20
|
const pass = await waitUntil(async () => {
|
|
21
21
|
const result = await executeCommand.call(this, el, condition, options, [expectedValue, options]);
|
|
@@ -23,7 +23,7 @@ export async function toHaveElementProperty(received, property, value, options =
|
|
|
23
23
|
expectedValue: [property, value],
|
|
24
24
|
options,
|
|
25
25
|
});
|
|
26
|
-
let el = await received
|
|
26
|
+
let el = await received?.getElement();
|
|
27
27
|
let prop;
|
|
28
28
|
const pass = await waitUntil(async () => {
|
|
29
29
|
const result = await executeCommand.call(this, el, condition, options, [property, value]);
|
|
@@ -16,9 +16,9 @@ export async function toHaveHTML(received, expectedValue, options = DEFAULT_OPTI
|
|
|
16
16
|
options,
|
|
17
17
|
});
|
|
18
18
|
let el = 'getElement' in received
|
|
19
|
-
? await received
|
|
19
|
+
? await received?.getElement()
|
|
20
20
|
: 'getElements' in received
|
|
21
|
-
? await received
|
|
21
|
+
? await received?.getElements()
|
|
22
22
|
: received;
|
|
23
23
|
let actualHTML;
|
|
24
24
|
const pass = await waitUntil(async () => {
|
|
@@ -15,7 +15,7 @@ export async function toHaveHeight(received, expectedValue, options = DEFAULT_OP
|
|
|
15
15
|
expectedValue,
|
|
16
16
|
options,
|
|
17
17
|
});
|
|
18
|
-
let el = await received
|
|
18
|
+
let el = await received?.getElement();
|
|
19
19
|
let actualHeight;
|
|
20
20
|
const pass = await waitUntil(async () => {
|
|
21
21
|
const result = await executeCommand.call(this, el, condition, options, [expectedValue, options]);
|
|
@@ -12,7 +12,7 @@ export async function toHaveSize(received, expectedValue, options = DEFAULT_OPTI
|
|
|
12
12
|
expectedValue,
|
|
13
13
|
options,
|
|
14
14
|
});
|
|
15
|
-
let el = await received
|
|
15
|
+
let el = await received?.getElement();
|
|
16
16
|
let actualSize;
|
|
17
17
|
const pass = await waitUntil(async () => {
|
|
18
18
|
const result = await executeCommand.call(this, el, condition, options, [expectedValue, options]);
|
|
@@ -11,7 +11,7 @@ export async function toHaveStyle(received, expectedValue, options = DEFAULT_OPT
|
|
|
11
11
|
expectedValue,
|
|
12
12
|
options,
|
|
13
13
|
});
|
|
14
|
-
let el = await received
|
|
14
|
+
let el = await received?.getElement();
|
|
15
15
|
let actualStyle;
|
|
16
16
|
const pass = await waitUntil(async () => {
|
|
17
17
|
const result = await executeCommand.call(this, el, condition, options, [expectedValue, options]);
|
|
@@ -36,9 +36,9 @@ export async function toHaveText(received, expectedValue, options = DEFAULT_OPTI
|
|
|
36
36
|
options,
|
|
37
37
|
});
|
|
38
38
|
let el = 'getElement' in received
|
|
39
|
-
? await received
|
|
39
|
+
? await received?.getElement()
|
|
40
40
|
: 'getElements' in received
|
|
41
|
-
? await received
|
|
41
|
+
? await received?.getElements()
|
|
42
42
|
: received;
|
|
43
43
|
let actualText;
|
|
44
44
|
const pass = await waitUntil(async () => {
|
|
@@ -15,7 +15,7 @@ export async function toHaveWidth(received, expectedValue, options = DEFAULT_OPT
|
|
|
15
15
|
expectedValue,
|
|
16
16
|
options,
|
|
17
17
|
});
|
|
18
|
-
let el = await received
|
|
18
|
+
let el = await received?.getElement();
|
|
19
19
|
let actualWidth;
|
|
20
20
|
const pass = await waitUntil(async () => {
|
|
21
21
|
const result = await executeCommand.call(this, el, condition, options, [expectedValue, options]);
|
package/lib/utils.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import isEqual from 'lodash.isequal';
|
|
2
|
+
import { expect } from './index.js';
|
|
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();
|
|
@@ -40,7 +44,7 @@ const waitUntil = async (condition, isNot = false, { wait = DEFAULT_OPTIONS.wait
|
|
|
40
44
|
}
|
|
41
45
|
return !isNot;
|
|
42
46
|
}
|
|
43
|
-
catch
|
|
47
|
+
catch {
|
|
44
48
|
if (error) {
|
|
45
49
|
throw error;
|
|
46
50
|
}
|
|
@@ -49,7 +53,7 @@ const waitUntil = async (condition, isNot = false, { wait = DEFAULT_OPTIONS.wait
|
|
|
49
53
|
};
|
|
50
54
|
async function executeCommandBe(received, command, options) {
|
|
51
55
|
const { isNot, expectation, verb = 'be' } = this;
|
|
52
|
-
let el = await received
|
|
56
|
+
let el = await received?.getElement();
|
|
53
57
|
const pass = await waitUntil(async () => {
|
|
54
58
|
const result = await executeCommand.call(this, el, async (element) => ({ result: await command(element) }), options);
|
|
55
59
|
el = result.el;
|
|
@@ -94,6 +98,11 @@ export const compareText = (actual, expected, { ignoreCase = false, trim = true,
|
|
|
94
98
|
if (typeof expected === 'string') {
|
|
95
99
|
expected = expected.toLowerCase();
|
|
96
100
|
}
|
|
101
|
+
else if (isStringContainingMatcher(expected)) {
|
|
102
|
+
expected = (expected.toString() === 'StringContaining'
|
|
103
|
+
? expect.stringContaining(expected.sample?.toString().toLowerCase())
|
|
104
|
+
: expect.not.stringContaining(expected.sample?.toString().toLowerCase()));
|
|
105
|
+
}
|
|
97
106
|
}
|
|
98
107
|
if (isAsymmeyricMatcher(expected)) {
|
|
99
108
|
const result = expected.asymmetricMatch(actual);
|
|
@@ -153,12 +162,25 @@ export const compareTextWithArray = (actual, expectedArray, { ignoreCase = false
|
|
|
153
162
|
}
|
|
154
163
|
if (ignoreCase) {
|
|
155
164
|
actual = actual.toLowerCase();
|
|
156
|
-
expectedArray = expectedArray.map((item) =>
|
|
165
|
+
expectedArray = expectedArray.map((item) => {
|
|
166
|
+
if (typeof item === 'string') {
|
|
167
|
+
return item.toLowerCase();
|
|
168
|
+
}
|
|
169
|
+
if (isStringContainingMatcher(item)) {
|
|
170
|
+
return (item.toString() === 'StringContaining'
|
|
171
|
+
? expect.stringContaining(item.sample?.toString().toLowerCase())
|
|
172
|
+
: expect.not.stringContaining(item.sample?.toString().toLowerCase()));
|
|
173
|
+
}
|
|
174
|
+
return item;
|
|
175
|
+
});
|
|
157
176
|
}
|
|
158
177
|
const textInArray = expectedArray.some((expected) => {
|
|
159
178
|
if (expected instanceof RegExp) {
|
|
160
179
|
return !!actual.match(expected);
|
|
161
180
|
}
|
|
181
|
+
if (isAsymmeyricMatcher(expected)) {
|
|
182
|
+
return expected.asymmetricMatch(actual);
|
|
183
|
+
}
|
|
162
184
|
if (containing) {
|
|
163
185
|
return actual.includes(expected);
|
|
164
186
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expect-webdriverio",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.1",
|
|
4
4
|
"author": "Mykola Grybyk <mykola.grybyk@gmail.com>",
|
|
5
5
|
"description": "WebdriverIO Assertion Library",
|
|
6
6
|
"license": "MIT",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"prepare": "husky install"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@vitest/snapshot": "^
|
|
61
|
+
"@vitest/snapshot": "^2.0.5",
|
|
62
62
|
"expect": "^29.7.0",
|
|
63
63
|
"jest-matcher-utils": "^29.7.0",
|
|
64
64
|
"lodash.isequal": "^4.5.0"
|
|
@@ -67,22 +67,22 @@
|
|
|
67
67
|
"@types/debug": "^4.1.12",
|
|
68
68
|
"@types/jest": "^29.5.12",
|
|
69
69
|
"@types/lodash.isequal": "^4.5.8",
|
|
70
|
-
"@types/node": "^
|
|
71
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
72
|
-
"@typescript-eslint/parser": "^
|
|
73
|
-
"@vitest/coverage-v8": "^
|
|
70
|
+
"@types/node": "^22.4.1",
|
|
71
|
+
"@typescript-eslint/eslint-plugin": "^8.1.0",
|
|
72
|
+
"@typescript-eslint/parser": "^8.1.0",
|
|
73
|
+
"@vitest/coverage-v8": "^2.0.5",
|
|
74
74
|
"c8": "^10.1.2",
|
|
75
75
|
"eslint": "^8.56.0",
|
|
76
76
|
"eslint-plugin-import": "^2.29.1",
|
|
77
|
-
"eslint-plugin-unicorn": "^
|
|
78
|
-
"husky": "^9.
|
|
79
|
-
"npm-run-all2": "^6.2.
|
|
80
|
-
"release-it": "^17.
|
|
81
|
-
"rimraf": "^
|
|
77
|
+
"eslint-plugin-unicorn": "^55.0.0",
|
|
78
|
+
"husky": "^9.1.4",
|
|
79
|
+
"npm-run-all2": "^6.2.2",
|
|
80
|
+
"release-it": "^17.6.0",
|
|
81
|
+
"rimraf": "^6.0.1",
|
|
82
82
|
"shelljs": "^0.8.5",
|
|
83
|
-
"typescript": "^5.5.
|
|
84
|
-
"vitest": "
|
|
85
|
-
"webdriverio": "9.0.
|
|
83
|
+
"typescript": "^5.5.4",
|
|
84
|
+
"vitest": "2.0.5",
|
|
85
|
+
"webdriverio": "9.0.4"
|
|
86
86
|
},
|
|
87
87
|
"peerDependencies": {
|
|
88
88
|
"@wdio/globals": "^9.0.0-alpha.350",
|