expect-webdriverio 1.3.1 → 2.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 +4 -461
- package/jasmine.d.ts +1 -1
- package/lib/addMatchers.js +6 -3
- package/lib/matchers/element/toHaveElementProperty.js +2 -7
- package/lib/matchers/element/toHaveText.js +3 -0
- package/lib/matchers/mock/toBeRequested.js +2 -15
- package/lib/matchers/mock/toBeRequestedTimes.js +12 -5
- package/lib/matchers/mock/toBeRequestedWith.js +218 -0
- package/lib/matchers/mock/toBeRequestedWithResponse.js +3 -24
- package/lib/matchers.js +1 -0
- package/lib/options.js +4 -2
- package/lib/util/elementsUtil.js +4 -2
- package/lib/util/expectAdapter.js +6 -3
- package/lib/util/formatMessage.js +14 -7
- package/lib/util/refetchElements.js +2 -1
- package/lib/utils.js +32 -3
- package/package.json +24 -26
- package/types/expect-webdriverio.d.ts +154 -91
- package/types/standalone.d.ts +15 -3
- package/lib/types/some-expect.js +0 -0
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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");
|
|
7
|
+
const STR_LIMIT = 80;
|
|
8
|
+
const KEY_LIMIT = 12;
|
|
9
|
+
function toBeRequestedWithFn(received, requestedWith = {}, options = {}) {
|
|
10
|
+
const isNot = this.isNot || false;
|
|
11
|
+
const { expectation = 'called with', verb = 'be' } = this;
|
|
12
|
+
return browser.call(async () => {
|
|
13
|
+
let actual;
|
|
14
|
+
const pass = await utils_1.waitUntil(async () => {
|
|
15
|
+
for (const call of received.calls) {
|
|
16
|
+
actual = call;
|
|
17
|
+
if (methodMatcher(call.method, requestedWith.method) &&
|
|
18
|
+
statusCodeMatcher(call.statusCode, requestedWith.statusCode) &&
|
|
19
|
+
urlMatcher(call.url, requestedWith.url) &&
|
|
20
|
+
headersMatcher(call.headers, requestedWith.requestHeaders) &&
|
|
21
|
+
headersMatcher(call.responseHeaders, requestedWith.responseHeaders) &&
|
|
22
|
+
bodyMatcher(call.postData, requestedWith.postData) &&
|
|
23
|
+
bodyMatcher(call.body, requestedWith.response)) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
}, isNot, { ...options, wait: isNot ? 0 : options.wait });
|
|
29
|
+
const message = utils_1.enhanceError('mock', minifyRequestedWith(requestedWith), minifyRequestMock(actual, requestedWith) || 'was not called', this, verb, expectation, '', options);
|
|
30
|
+
return {
|
|
31
|
+
pass,
|
|
32
|
+
message: () => message,
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
exports.toBeRequestedWithFn = toBeRequestedWithFn;
|
|
37
|
+
const methodMatcher = (method, expected) => {
|
|
38
|
+
if (typeof expected === 'undefined') {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
if (!Array.isArray(expected)) {
|
|
42
|
+
expected = [expected];
|
|
43
|
+
}
|
|
44
|
+
return expected
|
|
45
|
+
.map((m) => {
|
|
46
|
+
if (typeof m !== 'string') {
|
|
47
|
+
return console.error('expect.toBeRequestedWith: unsupported value passed to method ' + m);
|
|
48
|
+
}
|
|
49
|
+
return m.toUpperCase();
|
|
50
|
+
})
|
|
51
|
+
.includes(method);
|
|
52
|
+
};
|
|
53
|
+
const statusCodeMatcher = (statusCode, expected) => {
|
|
54
|
+
if (typeof expected === 'undefined') {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
if (!Array.isArray(expected)) {
|
|
58
|
+
expected = [expected];
|
|
59
|
+
}
|
|
60
|
+
return expected.includes(statusCode);
|
|
61
|
+
};
|
|
62
|
+
const urlMatcher = (url, expected) => {
|
|
63
|
+
if (typeof expected === 'undefined') {
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
if (typeof expected === 'function') {
|
|
67
|
+
return expected(url);
|
|
68
|
+
}
|
|
69
|
+
return jasmineUtils_1.equals(url, expected);
|
|
70
|
+
};
|
|
71
|
+
const headersMatcher = (headers, expected) => {
|
|
72
|
+
if (typeof expected === 'undefined') {
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
if (typeof expected === 'function') {
|
|
76
|
+
return expected(headers);
|
|
77
|
+
}
|
|
78
|
+
return jasmineUtils_1.equals(headers, expected);
|
|
79
|
+
};
|
|
80
|
+
const bodyMatcher = (body, expected) => {
|
|
81
|
+
if (typeof expected === 'undefined') {
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
if (typeof expected === 'function') {
|
|
85
|
+
return expected(body);
|
|
86
|
+
}
|
|
87
|
+
if (typeof body === 'undefined') {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
let parsedBody = body;
|
|
91
|
+
if (body instanceof Buffer) {
|
|
92
|
+
parsedBody = body.toString();
|
|
93
|
+
}
|
|
94
|
+
if (typeof (body) === 'string' && isExpectedJsonLike(expected)) {
|
|
95
|
+
parsedBody = tryParseBody(body);
|
|
96
|
+
if (parsedBody === null) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return jasmineUtils_1.equals(parsedBody, expected);
|
|
101
|
+
};
|
|
102
|
+
const isExpectedJsonLike = (expected) => {
|
|
103
|
+
if (typeof expected === 'undefined') {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
const actualSample = isMatcher(expected)
|
|
107
|
+
? expected.sample
|
|
108
|
+
: expected;
|
|
109
|
+
return (Array.isArray(actualSample) ||
|
|
110
|
+
(typeof actualSample === 'object' &&
|
|
111
|
+
actualSample !== null &&
|
|
112
|
+
actualSample instanceof RegExp === false));
|
|
113
|
+
};
|
|
114
|
+
const isMatcher = (filter) => {
|
|
115
|
+
var _a;
|
|
116
|
+
return typeof ((_a = filter.__proto__) === null || _a === void 0 ? void 0 : _a.asymmetricMatch) === 'function';
|
|
117
|
+
};
|
|
118
|
+
const tryParseBody = (jsonString, fallback = null) => {
|
|
119
|
+
try {
|
|
120
|
+
return typeof jsonString === 'undefined' ? fallback : JSON.parse(jsonString);
|
|
121
|
+
}
|
|
122
|
+
catch (_a) {
|
|
123
|
+
return fallback;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
const minifyRequestMock = (requestMock, requestedWith) => {
|
|
127
|
+
if (typeof requestMock === 'undefined') {
|
|
128
|
+
return requestMock;
|
|
129
|
+
}
|
|
130
|
+
const r = {
|
|
131
|
+
url: requestMock.url,
|
|
132
|
+
method: requestMock.method,
|
|
133
|
+
requestHeaders: requestMock.headers,
|
|
134
|
+
responseHeaders: requestMock.responseHeaders,
|
|
135
|
+
postData: typeof requestMock.postData === 'string' && isExpectedJsonLike(requestedWith.postData)
|
|
136
|
+
? tryParseBody(requestMock.postData, requestMock.postData)
|
|
137
|
+
: requestMock.postData,
|
|
138
|
+
response: typeof requestMock.body === 'string' && isExpectedJsonLike(requestedWith.response)
|
|
139
|
+
? tryParseBody(requestMock.body, requestMock.body)
|
|
140
|
+
: requestMock.body,
|
|
141
|
+
};
|
|
142
|
+
deleteUndefinedValues(r, requestedWith);
|
|
143
|
+
return minifyRequestedWith(r);
|
|
144
|
+
};
|
|
145
|
+
const minifyRequestedWith = (r) => {
|
|
146
|
+
const result = {
|
|
147
|
+
url: requestedWithParamToString(r.url),
|
|
148
|
+
method: r.method,
|
|
149
|
+
requestHeaders: requestedWithParamToString(r.requestHeaders, shortenJson),
|
|
150
|
+
responseHeaders: requestedWithParamToString(r.responseHeaders, shortenJson),
|
|
151
|
+
postData: requestedWithParamToString(r.postData, shortenJson),
|
|
152
|
+
response: requestedWithParamToString(r.response, shortenJson),
|
|
153
|
+
};
|
|
154
|
+
deleteUndefinedValues(result);
|
|
155
|
+
return result;
|
|
156
|
+
};
|
|
157
|
+
const requestedWithParamToString = (param, transformFn) => {
|
|
158
|
+
if (typeof param === 'undefined') {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
if (typeof param === 'function') {
|
|
162
|
+
param = param.toString();
|
|
163
|
+
}
|
|
164
|
+
else if (isMatcher(param)) {
|
|
165
|
+
return (param.constructor.name +
|
|
166
|
+
' ' +
|
|
167
|
+
(JSON.stringify(param.sample) || ''));
|
|
168
|
+
}
|
|
169
|
+
else if (transformFn && typeof param === 'object' && param !== null) {
|
|
170
|
+
param = transformFn(param);
|
|
171
|
+
}
|
|
172
|
+
if (typeof param === 'string') {
|
|
173
|
+
param = shortenString(param);
|
|
174
|
+
}
|
|
175
|
+
return param;
|
|
176
|
+
};
|
|
177
|
+
const shortenJson = (obj, lengthLimit = STR_LIMIT * 2, keyLimit = KEY_LIMIT) => {
|
|
178
|
+
if (JSON.stringify(obj).length < lengthLimit) {
|
|
179
|
+
return obj;
|
|
180
|
+
}
|
|
181
|
+
if (Array.isArray(obj)) {
|
|
182
|
+
const firstItem = typeof obj[0] === 'object' && obj[0] !== null
|
|
183
|
+
? shortenJson(obj[0], lengthLimit / 2, keyLimit / 4)
|
|
184
|
+
: shortenString(JSON.stringify(obj[0]));
|
|
185
|
+
return [firstItem, `... ${obj.length - 1} more items`];
|
|
186
|
+
}
|
|
187
|
+
const minifiedObject = {};
|
|
188
|
+
const entries = Object.entries(obj);
|
|
189
|
+
if (keyLimit >= 4) {
|
|
190
|
+
entries.slice(0, keyLimit).forEach(([k, v]) => {
|
|
191
|
+
if (typeof v === 'object' && v !== null) {
|
|
192
|
+
v = shortenJson(v, lengthLimit / 2, keyLimit / 4);
|
|
193
|
+
}
|
|
194
|
+
else if (typeof v === 'string') {
|
|
195
|
+
v = shortenString(v, 16);
|
|
196
|
+
}
|
|
197
|
+
minifiedObject[shortenString(k, 24)] = v;
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
if (entries.length > keyLimit) {
|
|
201
|
+
minifiedObject['...'] = `${entries.length} items in total`;
|
|
202
|
+
}
|
|
203
|
+
return minifiedObject;
|
|
204
|
+
};
|
|
205
|
+
const shortenString = (str, limit = STR_LIMIT) => {
|
|
206
|
+
return str.length > limit ? str.substring(0, limit / 2 - 1) + '..' + str.substr(1 - limit / 2) : str;
|
|
207
|
+
};
|
|
208
|
+
const deleteUndefinedValues = (obj, baseline = obj) => {
|
|
209
|
+
Object.keys(obj).forEach((k) => {
|
|
210
|
+
if (typeof baseline[k] === 'undefined') {
|
|
211
|
+
delete obj[k];
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
};
|
|
215
|
+
function toBeRequestedWith(...args) {
|
|
216
|
+
return expectAdapter_1.runExpect.call(this, toBeRequestedWithFn, args);
|
|
217
|
+
}
|
|
218
|
+
exports.toBeRequestedWith = toBeRequestedWith;
|
|
@@ -1,34 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.toBeRequestedWithResponse = void 0;
|
|
4
|
-
const
|
|
4
|
+
const toBeRequestedWith_1 = require("./toBeRequestedWith");
|
|
5
5
|
const expectAdapter_1 = require("../../util/expectAdapter");
|
|
6
|
-
const jasmineUtils_1 = require("../../jasmineUtils");
|
|
7
6
|
function toBeRequestedWithResponseFn(received, response, options = {}) {
|
|
8
|
-
|
|
9
|
-
const { expectation = 'called', verb = 'be' } = this;
|
|
10
|
-
return browser.call(async () => {
|
|
11
|
-
let actual;
|
|
12
|
-
const pass = await utils_1.waitUntil(async () => {
|
|
13
|
-
if (received.calls.length === 0) {
|
|
14
|
-
return isNot;
|
|
15
|
-
}
|
|
16
|
-
if (isNot) {
|
|
17
|
-
return !received.calls.reduce((res, mock) => res || jasmineUtils_1.equals(mock === null || mock === void 0 ? void 0 : mock.body, response), false);
|
|
18
|
-
}
|
|
19
|
-
return Boolean(received.calls.find((mock) => {
|
|
20
|
-
actual = mock === null || mock === void 0 ? void 0 : mock.body;
|
|
21
|
-
return !isNot === jasmineUtils_1.equals(mock === null || mock === void 0 ? void 0 : mock.body, response);
|
|
22
|
-
}));
|
|
23
|
-
});
|
|
24
|
-
const message = utils_1.enhanceError('mock', response, actual, this, verb, expectation, '', options);
|
|
25
|
-
return {
|
|
26
|
-
pass,
|
|
27
|
-
message: () => message
|
|
28
|
-
};
|
|
29
|
-
});
|
|
7
|
+
return toBeRequestedWith_1.toBeRequestedWithFn.call(this, received, { response }, options);
|
|
30
8
|
}
|
|
31
9
|
function toBeRequestedWithResponse(...args) {
|
|
10
|
+
console.warn('expect(...).toBeRequestedWithResponse is deprecated and will be removed in next release. Use toBeRequestedWith instead.');
|
|
32
11
|
return expectAdapter_1.runExpect.call(this, toBeRequestedWithResponseFn, args);
|
|
33
12
|
}
|
|
34
13
|
exports.toBeRequestedWithResponse = toBeRequestedWithResponse;
|
package/lib/matchers.js
CHANGED
|
@@ -29,6 +29,7 @@ const matchers = {
|
|
|
29
29
|
...require('./matchers/element/toHaveValueContaining'),
|
|
30
30
|
...require('./matchers/mock/toBeRequested'),
|
|
31
31
|
...require('./matchers/mock/toBeRequestedTimes'),
|
|
32
|
+
...require('./matchers/mock/toBeRequestedWith'),
|
|
32
33
|
...require('./matchers/mock/toBeRequestedWithResponse'),
|
|
33
34
|
};
|
|
34
35
|
Object.keys(matchers).forEach(key => {
|
package/lib/options.js
CHANGED
|
@@ -21,11 +21,13 @@ else {
|
|
|
21
21
|
if (!expectLib._expectWebdriverio) {
|
|
22
22
|
expectLib._expectWebdriverio = { options: { ...DEFAULT_OPTIONS }, mode };
|
|
23
23
|
}
|
|
24
|
-
|
|
25
|
-
exports.
|
|
24
|
+
const getConfig = () => expectLib._expectWebdriverio;
|
|
25
|
+
exports.getConfig = getConfig;
|
|
26
|
+
const setDefaultOptions = (options = {}) => {
|
|
26
27
|
Object.entries(options).forEach(([key, value]) => {
|
|
27
28
|
if (key in DEFAULT_OPTIONS) {
|
|
28
29
|
expectLib._expectWebdriverio.options[key] = value;
|
|
29
30
|
}
|
|
30
31
|
});
|
|
31
32
|
};
|
|
33
|
+
exports.setDefaultOptions = setDefaultOptions;
|
package/lib/util/elementsUtil.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.updateElementsArray = exports.wrapExpectedWithArray = void 0;
|
|
4
|
-
|
|
4
|
+
const wrapExpectedWithArray = (el, actual, expected) => {
|
|
5
5
|
if (Array.isArray(el) && el.length > 1 && Array.isArray(actual)) {
|
|
6
6
|
expected = [expected];
|
|
7
7
|
}
|
|
8
8
|
return expected;
|
|
9
9
|
};
|
|
10
|
-
exports.
|
|
10
|
+
exports.wrapExpectedWithArray = wrapExpectedWithArray;
|
|
11
|
+
const updateElementsArray = (success, received, refetched, full = false) => {
|
|
11
12
|
if (!success) {
|
|
12
13
|
return;
|
|
13
14
|
}
|
|
@@ -22,3 +23,4 @@ exports.updateElementsArray = (success, received, refetched, full = false) => {
|
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
25
|
};
|
|
26
|
+
exports.updateElementsArray = updateElementsArray;
|
|
@@ -4,22 +4,25 @@ exports.runExpect = exports.jestResultToJasmine = exports.buildJasmineFromJestRe
|
|
|
4
4
|
const options_1 = require("../options");
|
|
5
5
|
const config = options_1.getConfig();
|
|
6
6
|
const { mode: MODE } = config;
|
|
7
|
-
|
|
7
|
+
const getContext = (context) => global === context ? {} : context || {};
|
|
8
|
+
exports.getContext = getContext;
|
|
8
9
|
function runJestExpect(fn, args) {
|
|
9
10
|
return fn.apply(this, args);
|
|
10
11
|
}
|
|
11
|
-
|
|
12
|
+
const buildJasmineFromJestResult = (result, isNot) => {
|
|
12
13
|
return {
|
|
13
14
|
pass: result.pass !== isNot,
|
|
14
15
|
message: result.message()
|
|
15
16
|
};
|
|
16
17
|
};
|
|
17
|
-
exports.
|
|
18
|
+
exports.buildJasmineFromJestResult = buildJasmineFromJestResult;
|
|
19
|
+
const jestResultToJasmine = (result, isNot) => {
|
|
18
20
|
if (result instanceof Promise) {
|
|
19
21
|
return result.then(jestStyleResult => exports.buildJasmineFromJestResult(jestStyleResult, isNot));
|
|
20
22
|
}
|
|
21
23
|
return exports.buildJasmineFromJestResult(result, isNot);
|
|
22
24
|
};
|
|
25
|
+
exports.jestResultToJasmine = jestResultToJasmine;
|
|
23
26
|
function runJasmineExpect(fn) {
|
|
24
27
|
const context = exports.getContext(this);
|
|
25
28
|
return {
|
|
@@ -2,18 +2,20 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.numberError = exports.enhanceErrorBe = exports.enhanceError = exports.not = exports.getSelectors = exports.getSelector = void 0;
|
|
4
4
|
const jest_matcher_utils_1 = require("jest-matcher-utils");
|
|
5
|
+
const jasmineUtils_1 = require("../jasmineUtils");
|
|
5
6
|
const EXPECTED_LABEL = 'Expected';
|
|
6
7
|
const RECEIVED_LABEL = 'Received';
|
|
7
8
|
const NOT_SUFFIX = ' [not]';
|
|
8
9
|
const NOT_EXPECTED_LABEL = EXPECTED_LABEL + NOT_SUFFIX;
|
|
9
|
-
|
|
10
|
+
const getSelector = (el) => {
|
|
10
11
|
let result = typeof el.selector === 'string' ? el.selector : '<fn>';
|
|
11
12
|
if (Array.isArray(el) && el.props.length > 0) {
|
|
12
13
|
result += ', <props>';
|
|
13
14
|
}
|
|
14
15
|
return result;
|
|
15
16
|
};
|
|
16
|
-
exports.
|
|
17
|
+
exports.getSelector = getSelector;
|
|
18
|
+
const getSelectors = (el) => {
|
|
17
19
|
const selectors = [];
|
|
18
20
|
let parent;
|
|
19
21
|
if (Array.isArray(el)) {
|
|
@@ -31,10 +33,12 @@ exports.getSelectors = (el) => {
|
|
|
31
33
|
}
|
|
32
34
|
return selectors.reverse().join('.');
|
|
33
35
|
};
|
|
34
|
-
exports.
|
|
36
|
+
exports.getSelectors = getSelectors;
|
|
37
|
+
const not = (isNot) => {
|
|
35
38
|
return `${isNot ? 'not ' : ''}`;
|
|
36
39
|
};
|
|
37
|
-
exports.
|
|
40
|
+
exports.not = not;
|
|
41
|
+
const enhanceError = (subject, expected, actual, context, verb, expectation, arg2 = '', { message = '', containing = false }) => {
|
|
38
42
|
const { isNot = false } = context;
|
|
39
43
|
subject = typeof subject === 'string' ? subject : exports.getSelectors(subject);
|
|
40
44
|
let contain = '';
|
|
@@ -45,7 +49,7 @@ exports.enhanceError = (subject, expected, actual, context, verb, expectation, a
|
|
|
45
49
|
verb += ' ';
|
|
46
50
|
}
|
|
47
51
|
let diffString;
|
|
48
|
-
if (isNot && actual
|
|
52
|
+
if (isNot && jasmineUtils_1.equals(actual, expected)) {
|
|
49
53
|
diffString = `${EXPECTED_LABEL}: ${jest_matcher_utils_1.printExpected(expected)}\n` +
|
|
50
54
|
`${RECEIVED_LABEL}: ${jest_matcher_utils_1.printReceived(actual)}`;
|
|
51
55
|
}
|
|
@@ -66,10 +70,12 @@ exports.enhanceError = (subject, expected, actual, context, verb, expectation, a
|
|
|
66
70
|
const msg = `${message}Expect ${subject} ${exports.not(isNot)}to ${verb}${expectation}${arg2}${contain}\n\n${diffString}`;
|
|
67
71
|
return msg;
|
|
68
72
|
};
|
|
69
|
-
exports.
|
|
73
|
+
exports.enhanceError = enhanceError;
|
|
74
|
+
const enhanceErrorBe = (subject, pass, context, verb, expectation, options) => {
|
|
70
75
|
return exports.enhanceError(subject, exports.not(context.isNot) + expectation, exports.not(!pass) + expectation, context, verb, expectation, '', options);
|
|
71
76
|
};
|
|
72
|
-
exports.
|
|
77
|
+
exports.enhanceErrorBe = enhanceErrorBe;
|
|
78
|
+
const numberError = (gte, lte, eq) => {
|
|
73
79
|
if (typeof eq === 'number') {
|
|
74
80
|
return eq;
|
|
75
81
|
}
|
|
@@ -78,3 +84,4 @@ exports.numberError = (gte, lte, eq) => {
|
|
|
78
84
|
error += lte ? ` && <= ${lte}` : '';
|
|
79
85
|
return error;
|
|
80
86
|
};
|
|
87
|
+
exports.numberError = numberError;
|
|
@@ -4,7 +4,7 @@ exports.refetchElements = void 0;
|
|
|
4
4
|
const options_1 = require("../options");
|
|
5
5
|
const config = options_1.getConfig();
|
|
6
6
|
const { options: DEFAULT_OPTIONS } = config;
|
|
7
|
-
|
|
7
|
+
const refetchElements = async (elements, wait = DEFAULT_OPTIONS.wait, full = false) => {
|
|
8
8
|
if (elements) {
|
|
9
9
|
if (wait > 0 && (elements.length === 0 || full)) {
|
|
10
10
|
elements = await elements.parent[elements.foundWith](elements.selector, ...elements.props);
|
|
@@ -12,3 +12,4 @@ exports.refetchElements = async (elements, wait = DEFAULT_OPTIONS.wait, full = f
|
|
|
12
12
|
}
|
|
13
13
|
return elements;
|
|
14
14
|
};
|
|
15
|
+
exports.refetchElements = refetchElements;
|
package/lib/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.aliasFn = exports.compareNumbers = exports.waitUntil = exports.executeCommandBe = exports.executeCommand = exports.numberError = exports.enhanceError = exports.wrapExpectedWithArray = exports.updateElementsArray = exports.compareText = void 0;
|
|
3
|
+
exports.aliasFn = exports.compareNumbers = exports.waitUntil = exports.executeCommandBe = exports.executeCommand = exports.numberError = exports.enhanceError = exports.wrapExpectedWithArray = exports.updateElementsArray = exports.compareTextWithArray = exports.compareText = void 0;
|
|
4
4
|
const options_1 = require("./options");
|
|
5
5
|
const executeCommand_1 = require("./util/executeCommand");
|
|
6
6
|
Object.defineProperty(exports, "executeCommand", { enumerable: true, get: function () { return executeCommand_1.executeCommand; } });
|
|
@@ -44,7 +44,8 @@ const waitUntil = async (condition, isNot = false, { wait = DEFAULT_OPTIONS.wait
|
|
|
44
44
|
exports.waitUntil = waitUntil;
|
|
45
45
|
async function executeCommandBe(received, command, options) {
|
|
46
46
|
const { isNot, expectation, verb = 'be' } = this;
|
|
47
|
-
|
|
47
|
+
received = await received;
|
|
48
|
+
let el = received;
|
|
48
49
|
const pass = await waitUntil(async () => {
|
|
49
50
|
const result = await executeCommand_1.executeCommand.call(this, el, async (element) => ({ result: await command(element) }), options);
|
|
50
51
|
el = result.el;
|
|
@@ -68,7 +69,7 @@ const compareNumbers = (actual, gte, lte, eq) => {
|
|
|
68
69
|
return actual >= gte;
|
|
69
70
|
};
|
|
70
71
|
exports.compareNumbers = compareNumbers;
|
|
71
|
-
|
|
72
|
+
const compareText = (actual, expected, { ignoreCase = false, trim = false, containing = false }) => {
|
|
72
73
|
if (typeof actual !== 'string') {
|
|
73
74
|
return {
|
|
74
75
|
value: actual,
|
|
@@ -93,6 +94,34 @@ exports.compareText = (actual, expected, { ignoreCase = false, trim = false, con
|
|
|
93
94
|
result: actual === expected
|
|
94
95
|
};
|
|
95
96
|
};
|
|
97
|
+
exports.compareText = compareText;
|
|
98
|
+
const compareTextWithArray = (actual, expectedArray, { ignoreCase = false, trim = false, containing = false }) => {
|
|
99
|
+
if (typeof actual !== 'string') {
|
|
100
|
+
return {
|
|
101
|
+
value: actual,
|
|
102
|
+
result: false
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
if (trim) {
|
|
106
|
+
actual = actual.trim();
|
|
107
|
+
}
|
|
108
|
+
if (ignoreCase) {
|
|
109
|
+
actual = actual.toLowerCase();
|
|
110
|
+
expectedArray = expectedArray.map(item => item.toLowerCase());
|
|
111
|
+
}
|
|
112
|
+
if (containing) {
|
|
113
|
+
const textInArray = expectedArray.some((t) => actual.includes(t));
|
|
114
|
+
return {
|
|
115
|
+
value: actual,
|
|
116
|
+
result: textInArray
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
value: actual,
|
|
121
|
+
result: expectedArray.includes(actual)
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
exports.compareTextWithArray = compareTextWithArray;
|
|
96
125
|
function aliasFn(fn, { verb, expectation } = {}, ...args) {
|
|
97
126
|
const context = expectAdapter_1.getContext(this);
|
|
98
127
|
context.verb = verb;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expect-webdriverio",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -9,10 +9,11 @@
|
|
|
9
9
|
"clean:build": "rimraf ./lib",
|
|
10
10
|
"clean:tests": "rimraf test-types/**/node_modules && rimraf test-types/**/dist",
|
|
11
11
|
"compile": "tsc --build tsconfig.build.json",
|
|
12
|
-
"release": "
|
|
13
|
-
"release:
|
|
14
|
-
"release:
|
|
15
|
-
"release:
|
|
12
|
+
"release": "release-it --github.release",
|
|
13
|
+
"release:ci": "npm run release -- --ci --npm.skipChecks --no-git.requireCleanWorkingDir",
|
|
14
|
+
"release:patch": "npm run release -- patch",
|
|
15
|
+
"release:minor": "npm run release -- minor",
|
|
16
|
+
"release:major": "npm run release -- major",
|
|
16
17
|
"test": "run-s test:*",
|
|
17
18
|
"test:lint": "eslint . --ext .js,.jsx,.ts,.tsx",
|
|
18
19
|
"test:unit": "jest",
|
|
@@ -21,7 +22,8 @@
|
|
|
21
22
|
"ts": "run-p ts:*",
|
|
22
23
|
"ts:default": "cd test-types/default && tsc --incremental",
|
|
23
24
|
"ts:jest": "cd test-types/jest && tsc --incremental",
|
|
24
|
-
"ts:jasmine": "cd test-types/jasmine && tsc --incremental"
|
|
25
|
+
"ts:jasmine": "cd test-types/jasmine && tsc --incremental",
|
|
26
|
+
"prepare": "husky install"
|
|
25
27
|
},
|
|
26
28
|
"repository": {
|
|
27
29
|
"type": "git",
|
|
@@ -40,32 +42,28 @@
|
|
|
40
42
|
},
|
|
41
43
|
"homepage": "https://github.com/webdriverio/expect-webdriverio#readme",
|
|
42
44
|
"devDependencies": {
|
|
43
|
-
"@types/jasmine": "^3.
|
|
44
|
-
"@types/jest": "^26.0.
|
|
45
|
-
"@types/node": "^14.
|
|
46
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
47
|
-
"@typescript-eslint/parser": "^
|
|
48
|
-
"codecov": "^3.
|
|
49
|
-
"eslint": "^7.
|
|
50
|
-
"husky": "^
|
|
51
|
-
"jest": "^26.
|
|
52
|
-
"np": "^6.3.2",
|
|
45
|
+
"@types/jasmine": "^3.6.6",
|
|
46
|
+
"@types/jest": "^26.0.20",
|
|
47
|
+
"@types/node": "^14.14.33",
|
|
48
|
+
"@typescript-eslint/eslint-plugin": "^4.17.0",
|
|
49
|
+
"@typescript-eslint/parser": "^4.17.0",
|
|
50
|
+
"codecov": "^3.8.1",
|
|
51
|
+
"eslint": "^7.21.0",
|
|
52
|
+
"husky": "^5.1.3",
|
|
53
|
+
"jest": "^26.6.3",
|
|
53
54
|
"npm-run-all": "^4.1.5",
|
|
55
|
+
"release-it": "^14.4.1",
|
|
54
56
|
"rimraf": "^3.0.2",
|
|
55
57
|
"shelljs": "^0.8.4",
|
|
56
|
-
"ts-jest": "^26.
|
|
57
|
-
"
|
|
58
|
-
"
|
|
58
|
+
"ts-jest": "^26.5.3",
|
|
59
|
+
"ts-node": "^9.1.1",
|
|
60
|
+
"typescript": "^4.2.3",
|
|
61
|
+
"webdriverio": "^7.1.1"
|
|
59
62
|
},
|
|
60
63
|
"types": "types/jest-global.d.ts",
|
|
61
64
|
"typeScriptVersion": "3.8.3",
|
|
62
|
-
"husky": {
|
|
63
|
-
"hooks": {
|
|
64
|
-
"pre-commit": "run-s compile"
|
|
65
|
-
}
|
|
66
|
-
},
|
|
67
65
|
"dependencies": {
|
|
68
|
-
"expect": "^26.
|
|
69
|
-
"jest-matcher-utils": "^26.
|
|
66
|
+
"expect": "^26.6.2",
|
|
67
|
+
"jest-matcher-utils": "^26.6.2"
|
|
70
68
|
}
|
|
71
69
|
}
|