expect-webdriverio 4.0.0 → 4.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/README.md +29 -9
- package/jasmine.d.ts +0 -1
- package/jest.d.ts +1 -1
- package/lib/constants.js +4 -0
- package/lib/index.js +14 -6
- package/lib/jasmineUtils.js +7 -17
- package/lib/matchers/browser/toHaveTitle.js +12 -23
- package/lib/matchers/browser/toHaveTitleContaining.js +3 -11
- package/lib/matchers/browser/toHaveUrl.js +12 -23
- package/lib/matchers/browser/toHaveUrlContaining.js +3 -11
- package/lib/matchers/element/toBeClickable.js +10 -21
- package/lib/matchers/element/toBeDisabled.js +3 -14
- package/lib/matchers/element/toBeDisplayed.js +10 -21
- package/lib/matchers/element/toBeDisplayedInViewport.js +10 -21
- package/lib/matchers/element/toBeEnabled.js +3 -14
- package/lib/matchers/element/toBeExisting.js +14 -27
- package/lib/matchers/element/toBeFocused.js +3 -14
- package/lib/matchers/element/toBeSelected.js +6 -19
- package/lib/matchers/element/toHaveAttribute.js +35 -46
- package/lib/matchers/element/toHaveAttributeContaining.js +4 -12
- package/lib/matchers/element/toHaveChildren.js +27 -39
- package/lib/matchers/element/toHaveClass.js +47 -0
- package/lib/matchers/element/toHaveClassContaining.js +10 -0
- package/lib/matchers/element/toHaveElementProperty.js +25 -36
- package/lib/matchers/element/toHaveHref.js +4 -13
- package/lib/matchers/element/toHaveHrefContaining.js +4 -12
- package/lib/matchers/element/toHaveId.js +3 -12
- package/lib/matchers/element/toHaveStyle.js +17 -28
- package/lib/matchers/element/toHaveText.js +18 -29
- package/lib/matchers/element/toHaveTextContaining.js +3 -11
- package/lib/matchers/element/toHaveValue.js +3 -12
- package/lib/matchers/element/toHaveValueContaining.js +3 -11
- package/lib/matchers/elements/toBeElementsArrayOfSize.js +16 -26
- package/lib/matchers/mock/toBeRequested.js +3 -11
- package/lib/matchers/mock/toBeRequestedTimes.js +17 -32
- package/lib/matchers/mock/toBeRequestedWith.js +30 -39
- package/lib/matchers.js +62 -35
- package/lib/types.js +1 -0
- package/lib/util/elementsUtil.js +2 -7
- package/lib/util/executeCommand.js +3 -7
- package/lib/util/formatMessage.js +17 -26
- package/lib/util/refetchElements.js +2 -8
- package/lib/utils.js +41 -49
- package/package.json +49 -44
- package/types/expect-webdriverio.d.ts +23 -22
- package/types/jest-global.d.ts +1 -1
- package/types/standalone.d.ts +2 -2
- package/lib/addMatchers.js +0 -48
- package/lib/matchers/element/toHaveElementClass.js +0 -60
- package/lib/matchers/element/toHaveElementClassContaining.js +0 -20
- package/lib/matchers/mock/toBeRequestedWithResponse.js +0 -13
- package/lib/options.js +0 -33
- package/lib/util/expectAdapter.js +0 -41
- package/types/standalone-global.d.ts +0 -9
|
@@ -1,39 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.toBeRequestedWith = exports.toBeRequestedWithFn = void 0;
|
|
4
|
-
const utils_1 = require("../../utils");
|
|
5
|
-
const expectAdapter_1 = require("../../util/expectAdapter");
|
|
6
|
-
const jasmineUtils_1 = require("../../jasmineUtils");
|
|
1
|
+
import { waitUntil, enhanceError } from '../../utils.js';
|
|
2
|
+
import { equals } from '../../jasmineUtils.js';
|
|
7
3
|
const STR_LIMIT = 80;
|
|
8
4
|
const KEY_LIMIT = 12;
|
|
9
|
-
function
|
|
5
|
+
export async function toBeRequestedWith(received, requestedWith = {}, options = {}) {
|
|
10
6
|
const isNot = this.isNot || false;
|
|
11
7
|
const { expectation = 'called with', verb = 'be' } = this;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
8
|
+
let actual;
|
|
9
|
+
const pass = await waitUntil(async () => {
|
|
10
|
+
for (const call of received.calls) {
|
|
11
|
+
actual = call;
|
|
12
|
+
if (methodMatcher(call.method, requestedWith.method) &&
|
|
13
|
+
statusCodeMatcher(call.statusCode, requestedWith.statusCode) &&
|
|
14
|
+
urlMatcher(call.url, requestedWith.url) &&
|
|
15
|
+
headersMatcher(call.headers, requestedWith.requestHeaders) &&
|
|
16
|
+
headersMatcher(call.responseHeaders, requestedWith.responseHeaders) &&
|
|
17
|
+
bodyMatcher(call.postData, requestedWith.postData) &&
|
|
18
|
+
bodyMatcher(call.body, requestedWith.response)) {
|
|
19
|
+
return true;
|
|
26
20
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
}, isNot, { ...options, wait: isNot ? 0 : options.wait });
|
|
24
|
+
const message = enhanceError('mock', minifyRequestedWith(requestedWith), minifyRequestMock(actual, requestedWith) || 'was not called', this, verb, expectation, '', options);
|
|
25
|
+
return {
|
|
26
|
+
pass,
|
|
27
|
+
message: () => message,
|
|
28
|
+
};
|
|
35
29
|
}
|
|
36
|
-
exports.toBeRequestedWithFn = toBeRequestedWithFn;
|
|
37
30
|
const methodMatcher = (method, expected) => {
|
|
38
31
|
if (typeof expected === 'undefined') {
|
|
39
32
|
return true;
|
|
@@ -66,7 +59,7 @@ const urlMatcher = (url, expected) => {
|
|
|
66
59
|
if (typeof expected === 'function') {
|
|
67
60
|
return expected(url);
|
|
68
61
|
}
|
|
69
|
-
return
|
|
62
|
+
return equals(url, expected);
|
|
70
63
|
};
|
|
71
64
|
const headersMatcher = (headers, expected) => {
|
|
72
65
|
if (typeof expected === 'undefined') {
|
|
@@ -75,7 +68,7 @@ const headersMatcher = (headers, expected) => {
|
|
|
75
68
|
if (typeof expected === 'function') {
|
|
76
69
|
return expected(headers);
|
|
77
70
|
}
|
|
78
|
-
return
|
|
71
|
+
return equals(headers, expected);
|
|
79
72
|
};
|
|
80
73
|
const bodyMatcher = (body, expected) => {
|
|
81
74
|
if (typeof expected === 'undefined') {
|
|
@@ -97,7 +90,7 @@ const bodyMatcher = (body, expected) => {
|
|
|
97
90
|
return false;
|
|
98
91
|
}
|
|
99
92
|
}
|
|
100
|
-
return
|
|
93
|
+
return equals(parsedBody, expected);
|
|
101
94
|
};
|
|
102
95
|
const isExpectedJsonLike = (expected) => {
|
|
103
96
|
if (typeof expected === 'undefined') {
|
|
@@ -112,14 +105,13 @@ const isExpectedJsonLike = (expected) => {
|
|
|
112
105
|
actualSample instanceof RegExp === false));
|
|
113
106
|
};
|
|
114
107
|
const isMatcher = (filter) => {
|
|
115
|
-
|
|
116
|
-
return typeof ((_a = filter.__proto__) === null || _a === void 0 ? void 0 : _a.asymmetricMatch) === 'function';
|
|
108
|
+
return typeof filter.__proto__?.asymmetricMatch === 'function';
|
|
117
109
|
};
|
|
118
110
|
const tryParseBody = (jsonString, fallback = null) => {
|
|
119
111
|
try {
|
|
120
112
|
return typeof jsonString === 'undefined' ? fallback : JSON.parse(jsonString);
|
|
121
113
|
}
|
|
122
|
-
catch
|
|
114
|
+
catch {
|
|
123
115
|
return fallback;
|
|
124
116
|
}
|
|
125
117
|
};
|
|
@@ -212,7 +204,6 @@ const deleteUndefinedValues = (obj, baseline = obj) => {
|
|
|
212
204
|
}
|
|
213
205
|
});
|
|
214
206
|
};
|
|
215
|
-
function
|
|
216
|
-
return
|
|
207
|
+
export function toBeRequestedWithResponse(...args) {
|
|
208
|
+
return toBeRequestedWith.call(this, ...args);
|
|
217
209
|
}
|
|
218
|
-
exports.toBeRequestedWith = toBeRequestedWith;
|
package/lib/matchers.js
CHANGED
|
@@ -1,41 +1,68 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import * as toHaveTitle from './matchers/browser/toHaveTitle.js';
|
|
2
|
+
import * as toHaveTitleContaining from './matchers/browser/toHaveTitleContaining.js';
|
|
3
|
+
import * as toHaveUrl from './matchers/browser/toHaveUrl.js';
|
|
4
|
+
import * as toHaveUrlContaining from './matchers/browser/toHaveUrlContaining.js';
|
|
5
|
+
import * as toBeElementsArrayOfSize from './matchers/elements/toBeElementsArrayOfSize.js';
|
|
6
|
+
import * as toBeClickable from './matchers/element/toBeClickable.js';
|
|
7
|
+
import * as toBeDisabled from './matchers/element/toBeDisabled.js';
|
|
8
|
+
import * as toBeDisplayed from './matchers/element/toBeDisplayed.js';
|
|
9
|
+
import * as toBeDisplayedInViewport from './matchers/element/toBeDisplayedInViewport.js';
|
|
10
|
+
import * as toBeEnabled from './matchers/element/toBeEnabled.js';
|
|
11
|
+
import * as toBeExisting from './matchers/element/toBeExisting.js';
|
|
12
|
+
import * as toBeFocused from './matchers/element/toBeFocused.js';
|
|
13
|
+
import * as toBeSelected from './matchers/element/toBeSelected.js';
|
|
14
|
+
import * as toHaveAttribute from './matchers/element/toHaveAttribute.js';
|
|
15
|
+
import * as toHaveAttributeContaining from './matchers/element/toHaveAttributeContaining.js';
|
|
16
|
+
import * as toHaveChildren from './matchers/element/toHaveChildren.js';
|
|
17
|
+
import * as toHaveClass from './matchers/element/toHaveClass.js';
|
|
18
|
+
import * as toHaveClassContaining from './matchers/element/toHaveClassContaining.js';
|
|
19
|
+
import * as toHaveHref from './matchers/element/toHaveHref.js';
|
|
20
|
+
import * as toHaveHrefContaining from './matchers/element/toHaveHrefContaining.js';
|
|
21
|
+
import * as toHaveId from './matchers/element/toHaveId.js';
|
|
22
|
+
import * as toHaveElementProperty from './matchers/element/toHaveElementProperty.js';
|
|
23
|
+
import * as toHaveText from './matchers/element/toHaveText.js';
|
|
24
|
+
import * as toHaveTextContaining from './matchers/element/toHaveTextContaining.js';
|
|
25
|
+
import * as toHaveValue from './matchers/element/toHaveValue.js';
|
|
26
|
+
import * as toHaveValueContaining from './matchers/element/toHaveValueContaining.js';
|
|
27
|
+
import * as toHaveStyle from './matchers/element/toHaveStyle.js';
|
|
28
|
+
import * as toBeRequested from './matchers/mock/toBeRequested.js';
|
|
29
|
+
import * as toBeRequestedTimes from './matchers/mock/toBeRequestedTimes.js';
|
|
30
|
+
import * as toBeRequestedWith from './matchers/mock/toBeRequestedWith.js';
|
|
3
31
|
const matchers = {
|
|
4
|
-
...
|
|
5
|
-
...
|
|
6
|
-
...
|
|
7
|
-
...
|
|
8
|
-
...
|
|
9
|
-
...
|
|
10
|
-
...
|
|
11
|
-
...
|
|
12
|
-
...
|
|
13
|
-
...
|
|
14
|
-
...
|
|
15
|
-
...
|
|
16
|
-
...
|
|
17
|
-
...
|
|
18
|
-
...
|
|
19
|
-
...
|
|
20
|
-
...
|
|
21
|
-
...
|
|
22
|
-
...
|
|
23
|
-
...
|
|
24
|
-
...
|
|
25
|
-
...
|
|
26
|
-
...
|
|
27
|
-
...
|
|
28
|
-
...
|
|
29
|
-
...
|
|
30
|
-
...
|
|
31
|
-
...
|
|
32
|
-
...
|
|
33
|
-
...
|
|
34
|
-
...require('./matchers/mock/toBeRequestedWithResponse'),
|
|
32
|
+
...toHaveTitle,
|
|
33
|
+
...toHaveTitleContaining,
|
|
34
|
+
...toHaveUrl,
|
|
35
|
+
...toHaveUrlContaining,
|
|
36
|
+
...toBeElementsArrayOfSize,
|
|
37
|
+
...toBeClickable,
|
|
38
|
+
...toBeDisabled,
|
|
39
|
+
...toBeDisplayed,
|
|
40
|
+
...toBeDisplayedInViewport,
|
|
41
|
+
...toBeEnabled,
|
|
42
|
+
...toBeExisting,
|
|
43
|
+
...toBeFocused,
|
|
44
|
+
...toBeSelected,
|
|
45
|
+
...toHaveAttribute,
|
|
46
|
+
...toHaveAttributeContaining,
|
|
47
|
+
...toHaveChildren,
|
|
48
|
+
...toHaveClass,
|
|
49
|
+
...toHaveClassContaining,
|
|
50
|
+
...toHaveHref,
|
|
51
|
+
...toHaveHrefContaining,
|
|
52
|
+
...toHaveId,
|
|
53
|
+
...toHaveElementProperty,
|
|
54
|
+
...toHaveText,
|
|
55
|
+
...toHaveTextContaining,
|
|
56
|
+
...toHaveValue,
|
|
57
|
+
...toHaveValueContaining,
|
|
58
|
+
...toHaveStyle,
|
|
59
|
+
...toBeRequested,
|
|
60
|
+
...toBeRequestedTimes,
|
|
61
|
+
...toBeRequestedWith,
|
|
35
62
|
};
|
|
36
|
-
Object.keys(matchers).forEach(key => {
|
|
63
|
+
Object.keys(matchers).forEach((key) => {
|
|
37
64
|
if (key.endsWith('Fn')) {
|
|
38
65
|
delete matchers[key];
|
|
39
66
|
}
|
|
40
67
|
});
|
|
41
|
-
|
|
68
|
+
export default matchers;
|
package/lib/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/util/elementsUtil.js
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.updateElementsArray = exports.wrapExpectedWithArray = void 0;
|
|
4
|
-
const wrapExpectedWithArray = (el, actual, expected) => {
|
|
1
|
+
export const wrapExpectedWithArray = (el, actual, expected) => {
|
|
5
2
|
if (Array.isArray(el) && el.length > 1 && Array.isArray(actual)) {
|
|
6
3
|
expected = [expected];
|
|
7
4
|
}
|
|
8
5
|
return expected;
|
|
9
6
|
};
|
|
10
|
-
|
|
11
|
-
const updateElementsArray = (success, received, refetched, full = false) => {
|
|
7
|
+
export const updateElementsArray = (success, received, refetched, full = false) => {
|
|
12
8
|
if (!success) {
|
|
13
9
|
return;
|
|
14
10
|
}
|
|
@@ -25,4 +21,3 @@ const updateElementsArray = (success, received, refetched, full = false) => {
|
|
|
25
21
|
}
|
|
26
22
|
}
|
|
27
23
|
};
|
|
28
|
-
exports.updateElementsArray = updateElementsArray;
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.executeCommand = void 0;
|
|
4
|
-
const refetchElements_1 = require("./refetchElements");
|
|
5
|
-
async function executeCommand(el, condition, options = {}, params = [], fullRefetch = false) {
|
|
1
|
+
import { refetchElements } from './refetchElements.js';
|
|
2
|
+
export async function executeCommand(el, condition, options = {}, params = [], fullRefetch = false) {
|
|
6
3
|
const { isNot = false } = this;
|
|
7
4
|
let elements;
|
|
8
5
|
if (Array.isArray(el)) {
|
|
9
|
-
elements = await
|
|
6
|
+
elements = await refetchElements(el, options.wait, fullRefetch);
|
|
10
7
|
}
|
|
11
8
|
else {
|
|
12
9
|
elements = [el];
|
|
@@ -28,4 +25,3 @@ async function executeCommand(el, condition, options = {}, params = [], fullRefe
|
|
|
28
25
|
values: values.length > 1 ? values : values[0]
|
|
29
26
|
};
|
|
30
27
|
}
|
|
31
|
-
exports.executeCommand = executeCommand;
|
|
@@ -1,46 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.numberError = exports.enhanceErrorBe = exports.enhanceError = exports.not = exports.getSelectors = exports.getSelector = void 0;
|
|
4
|
-
const jest_matcher_utils_1 = require("jest-matcher-utils");
|
|
5
|
-
const jasmineUtils_1 = require("../jasmineUtils");
|
|
1
|
+
import { printExpected, printReceived, printDiffOrStringify } from 'jest-matcher-utils';
|
|
2
|
+
import { equals } from '../jasmineUtils.js';
|
|
6
3
|
const EXPECTED_LABEL = 'Expected';
|
|
7
4
|
const RECEIVED_LABEL = 'Received';
|
|
8
5
|
const NOT_SUFFIX = ' [not]';
|
|
9
6
|
const NOT_EXPECTED_LABEL = EXPECTED_LABEL + NOT_SUFFIX;
|
|
10
|
-
const getSelector = (el) => {
|
|
7
|
+
export const getSelector = (el) => {
|
|
11
8
|
let result = typeof el.selector === 'string' ? el.selector : '<fn>';
|
|
12
9
|
if (Array.isArray(el) && el.props.length > 0) {
|
|
13
10
|
result += ', <props>';
|
|
14
11
|
}
|
|
15
12
|
return result;
|
|
16
13
|
};
|
|
17
|
-
|
|
18
|
-
const getSelectors = (el) => {
|
|
14
|
+
export const getSelectors = (el) => {
|
|
19
15
|
const selectors = [];
|
|
20
16
|
let parent;
|
|
21
17
|
if (Array.isArray(el)) {
|
|
22
|
-
selectors.push(`${el.foundWith}(\`${
|
|
18
|
+
selectors.push(`${el.foundWith}(\`${getSelector(el)}\`)`);
|
|
23
19
|
parent = el.parent;
|
|
24
20
|
}
|
|
25
21
|
else {
|
|
26
22
|
parent = el;
|
|
27
23
|
}
|
|
28
24
|
while (parent && 'selector' in parent) {
|
|
29
|
-
const selector =
|
|
25
|
+
const selector = getSelector(parent);
|
|
30
26
|
const index = parent.index ? `[${parent.index}]` : '';
|
|
31
27
|
selectors.push(`${parent.index ? '$' : ''}$(\`${selector}\`)${index}`);
|
|
32
28
|
parent = parent.parent;
|
|
33
29
|
}
|
|
34
30
|
return selectors.reverse().join('.');
|
|
35
31
|
};
|
|
36
|
-
|
|
37
|
-
const not = (isNot) => {
|
|
32
|
+
export const not = (isNot) => {
|
|
38
33
|
return `${isNot ? 'not ' : ''}`;
|
|
39
34
|
};
|
|
40
|
-
|
|
41
|
-
const enhanceError = (subject, expected, actual, context, verb, expectation, arg2 = '', { message = '', containing = false }) => {
|
|
35
|
+
export const enhanceError = (subject, expected, actual, context, verb, expectation, arg2 = '', { message = '', containing = false }) => {
|
|
42
36
|
const { isNot = false } = context;
|
|
43
|
-
subject = typeof subject === 'string' ? subject :
|
|
37
|
+
subject = typeof subject === 'string' ? subject : getSelectors(subject);
|
|
44
38
|
let contain = '';
|
|
45
39
|
if (containing) {
|
|
46
40
|
contain = ' containing';
|
|
@@ -49,12 +43,12 @@ const enhanceError = (subject, expected, actual, context, verb, expectation, arg
|
|
|
49
43
|
verb += ' ';
|
|
50
44
|
}
|
|
51
45
|
let diffString;
|
|
52
|
-
if (isNot &&
|
|
53
|
-
diffString = `${EXPECTED_LABEL}: ${
|
|
54
|
-
`${RECEIVED_LABEL}: ${
|
|
46
|
+
if (isNot && equals(actual, expected)) {
|
|
47
|
+
diffString = `${EXPECTED_LABEL}: ${printExpected(expected)}\n` +
|
|
48
|
+
`${RECEIVED_LABEL}: ${printReceived(actual)}`;
|
|
55
49
|
}
|
|
56
50
|
else {
|
|
57
|
-
diffString =
|
|
51
|
+
diffString = printDiffOrStringify(expected, actual, EXPECTED_LABEL, RECEIVED_LABEL, true);
|
|
58
52
|
}
|
|
59
53
|
if (isNot) {
|
|
60
54
|
diffString = diffString
|
|
@@ -67,15 +61,13 @@ const enhanceError = (subject, expected, actual, context, verb, expectation, arg
|
|
|
67
61
|
if (arg2) {
|
|
68
62
|
arg2 = ` ${arg2}`;
|
|
69
63
|
}
|
|
70
|
-
const msg = `${message}Expect ${subject} ${
|
|
64
|
+
const msg = `${message}Expect ${subject} ${not(isNot)}to ${verb}${expectation}${arg2}${contain}\n\n${diffString}`;
|
|
71
65
|
return msg;
|
|
72
66
|
};
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return exports.enhanceError(subject, exports.not(context.isNot) + expectation, exports.not(!pass) + expectation, context, verb, expectation, '', options);
|
|
67
|
+
export const enhanceErrorBe = (subject, pass, context, verb, expectation, options) => {
|
|
68
|
+
return enhanceError(subject, not(context.isNot) + expectation, not(!pass) + expectation, context, verb, expectation, '', options);
|
|
76
69
|
};
|
|
77
|
-
|
|
78
|
-
const numberError = (options = {}) => {
|
|
70
|
+
export const numberError = (options = {}) => {
|
|
79
71
|
if (options.eq) {
|
|
80
72
|
return options.eq;
|
|
81
73
|
}
|
|
@@ -90,4 +82,3 @@ const numberError = (options = {}) => {
|
|
|
90
82
|
}
|
|
91
83
|
return "no params";
|
|
92
84
|
};
|
|
93
|
-
exports.numberError = numberError;
|
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.refetchElements = void 0;
|
|
4
|
-
const options_1 = require("../options");
|
|
5
|
-
const config = options_1.getConfig();
|
|
6
|
-
const { options: DEFAULT_OPTIONS } = config;
|
|
7
|
-
const refetchElements = async (elements, wait = DEFAULT_OPTIONS.wait, full = false) => {
|
|
1
|
+
import { DEFAULT_OPTIONS } from '../constants.js';
|
|
2
|
+
export const refetchElements = async (elements, wait = DEFAULT_OPTIONS.wait, full = false) => {
|
|
8
3
|
if (elements) {
|
|
9
4
|
if (wait > 0 && (elements.length === 0 || full)) {
|
|
10
5
|
elements = await elements.parent[elements.foundWith](elements.selector, ...elements.props);
|
|
@@ -12,4 +7,3 @@ const refetchElements = async (elements, wait = DEFAULT_OPTIONS.wait, full = fal
|
|
|
12
7
|
}
|
|
13
8
|
return elements;
|
|
14
9
|
};
|
|
15
|
-
exports.refetchElements = refetchElements;
|
package/lib/utils.js
CHANGED
|
@@ -1,37 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
Object.defineProperty(exports, "executeCommand", { enumerable: true, get: function () { return executeCommand_1.executeCommand; } });
|
|
7
|
-
const elementsUtil_1 = require("./util/elementsUtil");
|
|
8
|
-
Object.defineProperty(exports, "wrapExpectedWithArray", { enumerable: true, get: function () { return elementsUtil_1.wrapExpectedWithArray; } });
|
|
9
|
-
Object.defineProperty(exports, "updateElementsArray", { enumerable: true, get: function () { return elementsUtil_1.updateElementsArray; } });
|
|
10
|
-
const formatMessage_1 = require("./util/formatMessage");
|
|
11
|
-
Object.defineProperty(exports, "enhanceError", { enumerable: true, get: function () { return formatMessage_1.enhanceError; } });
|
|
12
|
-
Object.defineProperty(exports, "numberError", { enumerable: true, get: function () { return formatMessage_1.numberError; } });
|
|
13
|
-
const expectAdapter_1 = require("./util/expectAdapter");
|
|
14
|
-
const config = options_1.getConfig();
|
|
15
|
-
const { options: DEFAULT_OPTIONS } = config;
|
|
1
|
+
import { executeCommand } from './util/executeCommand.js';
|
|
2
|
+
import { wrapExpectedWithArray, updateElementsArray } from './util/elementsUtil.js';
|
|
3
|
+
import { enhanceError, enhanceErrorBe, numberError } from './util/formatMessage.js';
|
|
4
|
+
import { DEFAULT_OPTIONS } from './constants.js';
|
|
5
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
16
6
|
const waitUntil = async (condition, isNot = false, { wait = DEFAULT_OPTIONS.wait, interval = DEFAULT_OPTIONS.interval } = {}) => {
|
|
17
7
|
if (wait === 0) {
|
|
18
8
|
return await condition();
|
|
19
9
|
}
|
|
20
10
|
try {
|
|
21
11
|
let error;
|
|
22
|
-
|
|
12
|
+
const start = Date.now();
|
|
13
|
+
while (true) {
|
|
14
|
+
if ((Date.now() - start) > wait) {
|
|
15
|
+
throw new Error('timeout');
|
|
16
|
+
}
|
|
23
17
|
error = undefined;
|
|
24
18
|
try {
|
|
25
|
-
|
|
19
|
+
const result = isNot !== await condition();
|
|
20
|
+
if (result) {
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
await sleep(interval);
|
|
26
24
|
}
|
|
27
25
|
catch (err) {
|
|
28
26
|
error = err;
|
|
29
|
-
|
|
27
|
+
await sleep(interval);
|
|
30
28
|
}
|
|
31
|
-
}
|
|
32
|
-
timeout: wait,
|
|
33
|
-
interval
|
|
34
|
-
});
|
|
29
|
+
}
|
|
35
30
|
if (error) {
|
|
36
31
|
throw error;
|
|
37
32
|
}
|
|
@@ -41,24 +36,22 @@ const waitUntil = async (condition, isNot = false, { wait = DEFAULT_OPTIONS.wait
|
|
|
41
36
|
return isNot;
|
|
42
37
|
}
|
|
43
38
|
};
|
|
44
|
-
exports.waitUntil = waitUntil;
|
|
45
39
|
async function executeCommandBe(received, command, options) {
|
|
46
40
|
const { isNot, expectation, verb = 'be' } = this;
|
|
47
41
|
received = await received;
|
|
48
42
|
let el = received;
|
|
49
43
|
const pass = await waitUntil(async () => {
|
|
50
|
-
const result = await
|
|
44
|
+
const result = await executeCommand.call(this, el, async (element) => ({ result: await command(element) }), options);
|
|
51
45
|
el = result.el;
|
|
52
46
|
return result.success;
|
|
53
47
|
}, isNot, options);
|
|
54
|
-
|
|
55
|
-
const message =
|
|
48
|
+
updateElementsArray(pass, received, el);
|
|
49
|
+
const message = enhanceErrorBe(el, pass, this, verb, expectation, options);
|
|
56
50
|
return {
|
|
57
51
|
pass,
|
|
58
52
|
message: () => message
|
|
59
53
|
};
|
|
60
54
|
}
|
|
61
|
-
exports.executeCommandBe = executeCommandBe;
|
|
62
55
|
const compareNumbers = (actual, options = {}) => {
|
|
63
56
|
if (typeof options.eq === 'number') {
|
|
64
57
|
return actual === options.eq;
|
|
@@ -74,8 +67,7 @@ const compareNumbers = (actual, options = {}) => {
|
|
|
74
67
|
}
|
|
75
68
|
return false;
|
|
76
69
|
};
|
|
77
|
-
|
|
78
|
-
const compareText = (actual, expected, { ignoreCase = false, trim = true, containing = false }) => {
|
|
70
|
+
export const compareText = (actual, expected, { ignoreCase = false, trim = true, containing = false }) => {
|
|
79
71
|
if (typeof actual !== 'string') {
|
|
80
72
|
return {
|
|
81
73
|
value: actual,
|
|
@@ -87,7 +79,15 @@ const compareText = (actual, expected, { ignoreCase = false, trim = true, contai
|
|
|
87
79
|
}
|
|
88
80
|
if (ignoreCase) {
|
|
89
81
|
actual = actual.toLowerCase();
|
|
90
|
-
expected
|
|
82
|
+
if (!(expected instanceof RegExp)) {
|
|
83
|
+
expected = expected.toLowerCase();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (expected instanceof RegExp) {
|
|
87
|
+
return {
|
|
88
|
+
value: actual,
|
|
89
|
+
result: !!actual.match(expected)
|
|
90
|
+
};
|
|
91
91
|
}
|
|
92
92
|
if (containing) {
|
|
93
93
|
return {
|
|
@@ -100,8 +100,7 @@ const compareText = (actual, expected, { ignoreCase = false, trim = true, contai
|
|
|
100
100
|
result: actual === expected
|
|
101
101
|
};
|
|
102
102
|
};
|
|
103
|
-
|
|
104
|
-
const compareTextWithArray = (actual, expectedArray, { ignoreCase = false, trim = false, containing = false }) => {
|
|
103
|
+
export const compareTextWithArray = (actual, expectedArray, { ignoreCase = false, trim = false, containing = false }) => {
|
|
105
104
|
if (typeof actual !== 'string') {
|
|
106
105
|
return {
|
|
107
106
|
value: actual,
|
|
@@ -113,22 +112,17 @@ const compareTextWithArray = (actual, expectedArray, { ignoreCase = false, trim
|
|
|
113
112
|
}
|
|
114
113
|
if (ignoreCase) {
|
|
115
114
|
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
|
-
};
|
|
115
|
+
expectedArray = expectedArray.map(item => (item instanceof RegExp) ? item : item.toLowerCase());
|
|
124
116
|
}
|
|
117
|
+
const textInArray = expectedArray.some((expected) => {
|
|
118
|
+
return expected instanceof RegExp ? !!actual.match(expected) : containing ? actual.includes(expected) : actual === expected;
|
|
119
|
+
});
|
|
125
120
|
return {
|
|
126
121
|
value: actual,
|
|
127
|
-
result:
|
|
122
|
+
result: textInArray
|
|
128
123
|
};
|
|
129
124
|
};
|
|
130
|
-
|
|
131
|
-
const compareStyle = async (actualEl, style, { ignoreCase = true, trim = false }) => {
|
|
125
|
+
export const compareStyle = async (actualEl, style, { ignoreCase = true, trim = false }) => {
|
|
132
126
|
let result = true;
|
|
133
127
|
const actual = {};
|
|
134
128
|
for (const key in style) {
|
|
@@ -151,11 +145,9 @@ const compareStyle = async (actualEl, style, { ignoreCase = true, trim = false }
|
|
|
151
145
|
result
|
|
152
146
|
};
|
|
153
147
|
};
|
|
154
|
-
exports.compareStyle = compareStyle;
|
|
155
148
|
function aliasFn(fn, { verb, expectation } = {}, ...args) {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
return fn.apply(context, args);
|
|
149
|
+
this.verb = verb;
|
|
150
|
+
this.expectation = expectation;
|
|
151
|
+
return fn.apply(this, args);
|
|
160
152
|
}
|
|
161
|
-
|
|
153
|
+
export { updateElementsArray, wrapExpectedWithArray, enhanceError, numberError, executeCommand, executeCommandBe, waitUntil, compareNumbers, aliasFn };
|