expect-webdriverio 4.11.10 → 4.12.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/toHaveAttribute.js +1 -3
- package/lib/matchers/element/toHaveChildren.js +1 -2
- package/lib/matchers/element/toHaveClass.js +2 -3
- package/lib/matchers/element/toHaveComputedLabel.js +1 -2
- package/lib/matchers/element/toHaveComputedRole.js +1 -2
- package/lib/matchers/element/toHaveElementProperty.js +1 -2
- package/lib/matchers/element/toHaveHTML.js +1 -2
- package/lib/matchers/element/toHaveHeight.js +1 -2
- package/lib/matchers/element/toHaveSize.js +1 -2
- package/lib/matchers/element/toHaveStyle.js +1 -2
- package/lib/matchers/element/toHaveText.js +1 -2
- package/lib/matchers/element/toHaveWidth.js +1 -2
- package/lib/matchers/elements/toBeElementsArrayOfSize.js +7 -5
- package/lib/util/elementsUtil.js +0 -17
- package/lib/util/executeCommand.js +5 -24
- package/lib/util/formatMessage.js +1 -1
- package/lib/utils.js +2 -3
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { waitUntil, enhanceError, compareText, executeCommand, wrapExpectedWithArray
|
|
1
|
+
import { waitUntil, enhanceError, compareText, executeCommand, wrapExpectedWithArray } from '../../utils.js';
|
|
2
2
|
import { DEFAULT_OPTIONS } from '../../constants.js';
|
|
3
3
|
async function conditionAttr(el, attribute) {
|
|
4
4
|
const attr = await el.getAttribute(attribute);
|
|
@@ -27,7 +27,6 @@ export async function toHaveAttributeAndValue(received, attribute, value, option
|
|
|
27
27
|
attr = result.values;
|
|
28
28
|
return result.success;
|
|
29
29
|
}, isNot, options);
|
|
30
|
-
updateElementsArray(pass, received, el);
|
|
31
30
|
const expected = wrapExpectedWithArray(el, attr, value);
|
|
32
31
|
const message = enhanceError(el, expected, attr, this, verb, expectation, attribute, options);
|
|
33
32
|
return {
|
|
@@ -44,7 +43,6 @@ async function toHaveAttributeFn(received, attribute) {
|
|
|
44
43
|
el = result.el;
|
|
45
44
|
return result.success;
|
|
46
45
|
}, isNot, {});
|
|
47
|
-
updateElementsArray(pass, received, el);
|
|
48
46
|
const message = enhanceError(el, !isNot, pass, this, verb, expectation, attribute, {});
|
|
49
47
|
return {
|
|
50
48
|
pass,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { waitUntil, enhanceError, compareNumbers, numberError, executeCommand, wrapExpectedWithArray
|
|
1
|
+
import { waitUntil, enhanceError, compareNumbers, numberError, executeCommand, wrapExpectedWithArray } from '../../utils.js';
|
|
2
2
|
import { DEFAULT_OPTIONS } from '../../constants.js';
|
|
3
3
|
async function condition(el, options) {
|
|
4
4
|
const children = await el.$$('./*');
|
|
@@ -34,7 +34,6 @@ export async function toHaveChildren(received, expectedValue, options = DEFAULT_
|
|
|
34
34
|
children = result.values;
|
|
35
35
|
return result.success;
|
|
36
36
|
}, isNot, { ...numberOptions, ...options });
|
|
37
|
-
updateElementsArray(pass, received, el);
|
|
38
37
|
const error = numberError(numberOptions);
|
|
39
38
|
const expectedArray = wrapExpectedWithArray(el, children, error);
|
|
40
39
|
const message = enhanceError(el, expectedArray, children, this, verb, expectation, '', numberOptions);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { toHaveAttributeAndValue } from './toHaveAttribute.js';
|
|
2
|
-
import { waitUntil, enhanceError, executeCommand, wrapExpectedWithArray,
|
|
2
|
+
import { waitUntil, enhanceError, executeCommand, wrapExpectedWithArray, compareText } from '../../utils.js';
|
|
3
3
|
import { DEFAULT_OPTIONS } from '../../constants.js';
|
|
4
4
|
async function condition(el, attribute, value, options) {
|
|
5
5
|
const { ignoreCase = false, trim = false, containing = false } = options;
|
|
6
|
-
let attr = await el.getAttribute(attribute);
|
|
6
|
+
let attr = await (await el).getAttribute(attribute);
|
|
7
7
|
if (typeof attr !== 'string') {
|
|
8
8
|
return { result: false };
|
|
9
9
|
}
|
|
@@ -49,7 +49,6 @@ export async function toHaveElementClass(received, expectedValue, options = DEFA
|
|
|
49
49
|
attr = result.values;
|
|
50
50
|
return result.success;
|
|
51
51
|
}, isNot, options);
|
|
52
|
-
updateElementsArray(pass, received, el);
|
|
53
52
|
const message = enhanceError(el, wrapExpectedWithArray(el, attr, expectedValue), attr, this, verb, expectation, '', options);
|
|
54
53
|
const result = {
|
|
55
54
|
pass,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { waitUntil, enhanceError, compareText, compareTextWithArray, executeCommand, wrapExpectedWithArray
|
|
1
|
+
import { waitUntil, enhanceError, compareText, compareTextWithArray, executeCommand, wrapExpectedWithArray } from '../../utils.js';
|
|
2
2
|
import { DEFAULT_OPTIONS } from '../../constants.js';
|
|
3
3
|
async function condition(el, label, options) {
|
|
4
4
|
const actualLabel = await el.getComputedLabel();
|
|
@@ -23,7 +23,6 @@ export async function toHaveComputedLabel(received, expectedValue, options = DEF
|
|
|
23
23
|
actualLabel = result.values;
|
|
24
24
|
return result.success;
|
|
25
25
|
}, isNot, options);
|
|
26
|
-
updateElementsArray(pass, received, el);
|
|
27
26
|
const message = enhanceError(el, wrapExpectedWithArray(el, actualLabel, expectedValue), actualLabel, this, verb, expectation, '', options);
|
|
28
27
|
const result = {
|
|
29
28
|
pass,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { waitUntil, enhanceError, compareText, compareTextWithArray, executeCommand, wrapExpectedWithArray
|
|
1
|
+
import { waitUntil, enhanceError, compareText, compareTextWithArray, executeCommand, wrapExpectedWithArray } from '../../utils.js';
|
|
2
2
|
import { DEFAULT_OPTIONS } from '../../constants.js';
|
|
3
3
|
async function condition(el, role, options) {
|
|
4
4
|
const actualRole = await el.getComputedRole();
|
|
@@ -23,7 +23,6 @@ export async function toHaveComputedRole(received, expectedValue, options = DEFA
|
|
|
23
23
|
actualRole = result.values;
|
|
24
24
|
return result.success;
|
|
25
25
|
}, isNot, options);
|
|
26
|
-
updateElementsArray(pass, received, el);
|
|
27
26
|
const message = enhanceError(el, wrapExpectedWithArray(el, actualRole, expectedValue), actualRole, this, verb, expectation, '', options);
|
|
28
27
|
const result = {
|
|
29
28
|
pass,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { waitUntil, enhanceError, compareText, executeCommand, wrapExpectedWithArray
|
|
1
|
+
import { waitUntil, enhanceError, compareText, executeCommand, wrapExpectedWithArray } from '../../utils.js';
|
|
2
2
|
import { DEFAULT_OPTIONS } from '../../constants.js';
|
|
3
3
|
async function condition(el, property, value, options = DEFAULT_OPTIONS) {
|
|
4
4
|
const { asString = false } = options;
|
|
@@ -31,7 +31,6 @@ export async function toHaveElementProperty(received, property, value, options =
|
|
|
31
31
|
prop = result.values;
|
|
32
32
|
return result.success;
|
|
33
33
|
}, isNot, options);
|
|
34
|
-
updateElementsArray(pass, received, el);
|
|
35
34
|
let message;
|
|
36
35
|
if (value === undefined) {
|
|
37
36
|
message = enhanceError(el, !isNot, pass, this, verb, expectation, property, options);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { waitUntil, enhanceError, compareText, compareTextWithArray, executeCommand, wrapExpectedWithArray
|
|
1
|
+
import { waitUntil, enhanceError, compareText, compareTextWithArray, executeCommand, wrapExpectedWithArray } from '../../utils.js';
|
|
2
2
|
import { DEFAULT_OPTIONS } from '../../constants.js';
|
|
3
3
|
async function condition(el, html, options) {
|
|
4
4
|
const actualHTML = await el.getHTML(options.includeSelectorTag);
|
|
@@ -23,7 +23,6 @@ export async function toHaveHTML(received, expectedValue, options = DEFAULT_OPTI
|
|
|
23
23
|
actualHTML = result.values;
|
|
24
24
|
return result.success;
|
|
25
25
|
}, isNot, options);
|
|
26
|
-
updateElementsArray(pass, received, el);
|
|
27
26
|
const message = enhanceError(el, wrapExpectedWithArray(el, actualHTML, expectedValue), actualHTML, this, verb, expectation, '', options);
|
|
28
27
|
const result = {
|
|
29
28
|
pass,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { waitUntil, enhanceError, executeCommand, wrapExpectedWithArray
|
|
1
|
+
import { waitUntil, enhanceError, executeCommand, wrapExpectedWithArray } from '../../utils.js';
|
|
2
2
|
import { DEFAULT_OPTIONS } from '../../constants.js';
|
|
3
3
|
async function condition(el, height) {
|
|
4
4
|
const actualHeight = await el.getSize('height');
|
|
@@ -23,7 +23,6 @@ export async function toHaveHeight(received, expectedValue, options = DEFAULT_OP
|
|
|
23
23
|
actualHeight = result.values;
|
|
24
24
|
return result.success;
|
|
25
25
|
}, isNot, options);
|
|
26
|
-
updateElementsArray(pass, received, el);
|
|
27
26
|
const message = enhanceError(el, wrapExpectedWithArray(el, actualHeight, expectedValue), actualHeight, this, verb, expectation, '', options);
|
|
28
27
|
const result = {
|
|
29
28
|
pass,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { waitUntil, enhanceError, executeCommand, wrapExpectedWithArray,
|
|
1
|
+
import { waitUntil, enhanceError, executeCommand, wrapExpectedWithArray, compareObject, } from '../../utils.js';
|
|
2
2
|
import { DEFAULT_OPTIONS } from '../../constants.js';
|
|
3
3
|
async function condition(el, size) {
|
|
4
4
|
const actualSize = await el.getSize();
|
|
@@ -20,7 +20,6 @@ export async function toHaveSize(received, expectedValue, options = DEFAULT_OPTI
|
|
|
20
20
|
actualSize = result.values;
|
|
21
21
|
return result.success;
|
|
22
22
|
}, isNot, options);
|
|
23
|
-
updateElementsArray(pass, received, el);
|
|
24
23
|
const message = enhanceError(el, wrapExpectedWithArray(el, actualSize, expectedValue), actualSize, this, verb, expectation, '', options);
|
|
25
24
|
const result = {
|
|
26
25
|
pass,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { waitUntil, enhanceError, compareStyle, executeCommand, wrapExpectedWithArray
|
|
1
|
+
import { waitUntil, enhanceError, compareStyle, executeCommand, wrapExpectedWithArray } from '../../utils.js';
|
|
2
2
|
import { DEFAULT_OPTIONS } from '../../constants.js';
|
|
3
3
|
async function condition(el, style, options) {
|
|
4
4
|
return compareStyle(el, style, options);
|
|
@@ -19,7 +19,6 @@ export async function toHaveStyle(received, expectedValue, options = DEFAULT_OPT
|
|
|
19
19
|
actualStyle = result.values;
|
|
20
20
|
return result.success;
|
|
21
21
|
}, isNot, options);
|
|
22
|
-
updateElementsArray(pass, received, el);
|
|
23
22
|
const message = enhanceError(el, wrapExpectedWithArray(el, actualStyle, expectedValue), actualStyle, this, verb, expectation, '', options);
|
|
24
23
|
const result = {
|
|
25
24
|
pass,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { waitUntil, enhanceError, compareText, compareTextWithArray, executeCommand, wrapExpectedWithArray
|
|
1
|
+
import { waitUntil, enhanceError, compareText, compareTextWithArray, executeCommand, wrapExpectedWithArray } from '../../utils.js';
|
|
2
2
|
import { DEFAULT_OPTIONS } from '../../constants.js';
|
|
3
3
|
async function condition(el, text, options) {
|
|
4
4
|
const actualText = await el.getText();
|
|
@@ -23,7 +23,6 @@ export async function toHaveText(received, expectedValue, options = DEFAULT_OPTI
|
|
|
23
23
|
actualText = result.values;
|
|
24
24
|
return result.success;
|
|
25
25
|
}, isNot, options);
|
|
26
|
-
updateElementsArray(pass, received, el);
|
|
27
26
|
const message = enhanceError(el, wrapExpectedWithArray(el, actualText, expectedValue), actualText, this, verb, expectation, '', options);
|
|
28
27
|
const result = {
|
|
29
28
|
pass,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { waitUntil, enhanceError, executeCommand, wrapExpectedWithArray
|
|
1
|
+
import { waitUntil, enhanceError, executeCommand, wrapExpectedWithArray } from '../../utils.js';
|
|
2
2
|
import { DEFAULT_OPTIONS } from '../../constants.js';
|
|
3
3
|
async function condition(el, width) {
|
|
4
4
|
const actualWidth = await el.getSize('width');
|
|
@@ -23,7 +23,6 @@ export async function toHaveWidth(received, expectedValue, options = DEFAULT_OPT
|
|
|
23
23
|
actualWidth = result.values;
|
|
24
24
|
return result.success;
|
|
25
25
|
}, isNot, options);
|
|
26
|
-
updateElementsArray(pass, received, el);
|
|
27
26
|
const message = enhanceError(el, wrapExpectedWithArray(el, actualWidth, expectedValue), actualWidth, this, verb, expectation, '', options);
|
|
28
27
|
const result = {
|
|
29
28
|
pass,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { waitUntil, enhanceError, compareNumbers, numberError
|
|
1
|
+
import { waitUntil, enhanceError, compareNumbers, numberError } from '../../utils.js';
|
|
2
2
|
import { refetchElements } from '../../util/refetchElements.js';
|
|
3
3
|
import { DEFAULT_OPTIONS } from '../../constants.js';
|
|
4
4
|
export async function toBeElementsArrayOfSize(received, expectedValue, options = DEFAULT_OPTIONS) {
|
|
@@ -20,14 +20,16 @@ export async function toBeElementsArrayOfSize(received, expectedValue, options =
|
|
|
20
20
|
numberOptions = expectedValue;
|
|
21
21
|
}
|
|
22
22
|
let elements = await received;
|
|
23
|
-
const arrLength = elements.length;
|
|
24
23
|
const pass = await waitUntil(async () => {
|
|
24
|
+
const isPassing = compareNumbers(elements.length, numberOptions);
|
|
25
|
+
if (isPassing) {
|
|
26
|
+
return isPassing;
|
|
27
|
+
}
|
|
25
28
|
elements = await refetchElements(elements, numberOptions.wait, true);
|
|
26
|
-
return
|
|
29
|
+
return false;
|
|
27
30
|
}, isNot, { ...numberOptions, ...options });
|
|
28
|
-
updateElementsArray(pass, received, elements, true);
|
|
29
31
|
const error = numberError(numberOptions);
|
|
30
|
-
const message = enhanceError(elements, error,
|
|
32
|
+
const message = enhanceError(elements, error, elements.length, this, verb, expectation, '', numberOptions);
|
|
31
33
|
const result = {
|
|
32
34
|
pass,
|
|
33
35
|
message: () => message
|
package/lib/util/elementsUtil.js
CHANGED
|
@@ -4,20 +4,3 @@ export const wrapExpectedWithArray = (el, actual, expected) => {
|
|
|
4
4
|
}
|
|
5
5
|
return expected;
|
|
6
6
|
};
|
|
7
|
-
export const updateElementsArray = (success, received, refetched, full = false) => {
|
|
8
|
-
if (!success) {
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
if (Array.isArray(received) && Array.isArray(refetched)) {
|
|
12
|
-
if (full === true) {
|
|
13
|
-
while (received.length > 0) {
|
|
14
|
-
received.pop();
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
if (received.length === 0) {
|
|
18
|
-
for (let i = 0; i < refetched.length; i++) {
|
|
19
|
-
received.push(refetched[i]);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
};
|
|
@@ -1,27 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const { isNot = false } = this;
|
|
4
|
-
let elements;
|
|
5
|
-
if (Array.isArray(el)) {
|
|
6
|
-
elements = await refetchElements(el, options.wait, fullRefetch);
|
|
7
|
-
}
|
|
8
|
-
else {
|
|
9
|
-
elements = [el];
|
|
10
|
-
}
|
|
11
|
-
if (elements.length === 0) {
|
|
12
|
-
return {
|
|
13
|
-
el: elements,
|
|
14
|
-
success: false,
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
const results = [];
|
|
18
|
-
for (const element of elements) {
|
|
19
|
-
results.push(await condition(element, ...params, options));
|
|
20
|
-
}
|
|
21
|
-
const values = [...new Set(results.filter(result => result.result === isNot).map(result => result.value))];
|
|
1
|
+
export async function executeCommand(el, condition, options = {}, params = []) {
|
|
2
|
+
const result = await condition(el, ...params, options);
|
|
22
3
|
return {
|
|
23
|
-
el
|
|
24
|
-
success:
|
|
25
|
-
values:
|
|
4
|
+
el,
|
|
5
|
+
success: result.result === true,
|
|
6
|
+
values: result.value
|
|
26
7
|
};
|
|
27
8
|
}
|
|
@@ -68,7 +68,7 @@ export const enhanceErrorBe = (subject, pass, context, verb, expectation, option
|
|
|
68
68
|
return enhanceError(subject, not(context.isNot) + expectation, not(!pass) + expectation, context, verb, expectation, '', options);
|
|
69
69
|
};
|
|
70
70
|
export const numberError = (options = {}) => {
|
|
71
|
-
if (options.eq) {
|
|
71
|
+
if (typeof options.eq === 'number') {
|
|
72
72
|
return options.eq;
|
|
73
73
|
}
|
|
74
74
|
if (options.gte && options.lte) {
|
package/lib/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import isEqual from 'lodash.isequal';
|
|
2
2
|
import { executeCommand } from './util/executeCommand.js';
|
|
3
|
-
import { wrapExpectedWithArray
|
|
3
|
+
import { wrapExpectedWithArray } from './util/elementsUtil.js';
|
|
4
4
|
import { enhanceError, enhanceErrorBe, numberError } from './util/formatMessage.js';
|
|
5
5
|
import { DEFAULT_OPTIONS } from './constants.js';
|
|
6
6
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -53,7 +53,6 @@ async function executeCommandBe(received, command, options) {
|
|
|
53
53
|
el = result.el;
|
|
54
54
|
return result.success;
|
|
55
55
|
}, isNot, options);
|
|
56
|
-
updateElementsArray(pass, received, el);
|
|
57
56
|
const message = enhanceErrorBe(el, pass, this, verb, expectation, options);
|
|
58
57
|
return {
|
|
59
58
|
pass,
|
|
@@ -217,7 +216,7 @@ function aliasFn(fn, { verb, expectation, } = {}, ...args) {
|
|
|
217
216
|
this.expectation = expectation;
|
|
218
217
|
return fn.apply(this, args);
|
|
219
218
|
}
|
|
220
|
-
export {
|
|
219
|
+
export { wrapExpectedWithArray, enhanceError, numberError, executeCommand, executeCommandBe, waitUntil, compareNumbers, aliasFn, };
|
|
221
220
|
function replaceActual(replace, actual) {
|
|
222
221
|
const hasMultipleReplacers = replace.every((r) => Array.isArray(r));
|
|
223
222
|
const replacers = hasMultipleReplacers
|