expect-webdriverio 5.6.5 → 5.6.7
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/util/formatMessage.js +22 -22
- package/lib/utils.js +2 -2
- package/package.json +5 -3
- package/types/expect-webdriverio.d.ts +1 -1
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import { printDiffOrStringify, printExpected, printReceived } from 'jest-matcher-utils';
|
|
2
2
|
import { equals } from '../jasmineUtils.js';
|
|
3
3
|
import { isElementArray } from './elementsUtil.js';
|
|
4
|
-
const EXPECTED_LABEL = 'Expected';
|
|
5
|
-
const RECEIVED_LABEL = 'Received';
|
|
6
|
-
const NOT_SUFFIX = ' [not]';
|
|
7
|
-
const NOT_EXPECTED_LABEL = EXPECTED_LABEL + NOT_SUFFIX;
|
|
8
4
|
export const getSelector = (el) => {
|
|
9
5
|
let result = typeof el.selector === 'string' ? el.selector : '<fn>';
|
|
10
6
|
if (Array.isArray(el) && el.props.length > 0) {
|
|
@@ -30,11 +26,9 @@ export const getSelectors = (el) => {
|
|
|
30
26
|
}
|
|
31
27
|
return selectors.reverse().join('.');
|
|
32
28
|
};
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
};
|
|
36
|
-
export const enhanceError = (subject, expected, actual, context, verb, expectation, arg2 = '', { message = '', containing = false }) => {
|
|
37
|
-
const { isNot = false } = context;
|
|
29
|
+
const not = (isNot) => `${isNot ? 'not ' : ''}`;
|
|
30
|
+
export const enhanceError = (subject, expected, actual, context, verb, expectation, expectedValueArgument2 = '', { message = '', containing = false } = {}) => {
|
|
31
|
+
const { isNot = false, useNotInLabel = true } = context;
|
|
38
32
|
subject = typeof subject === 'string' ? subject : getSelectors(subject);
|
|
39
33
|
let contain = '';
|
|
40
34
|
if (containing) {
|
|
@@ -43,25 +37,31 @@ export const enhanceError = (subject, expected, actual, context, verb, expectati
|
|
|
43
37
|
if (verb) {
|
|
44
38
|
verb += ' ';
|
|
45
39
|
}
|
|
46
|
-
|
|
47
|
-
?
|
|
48
|
-
:
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
40
|
+
const label = {
|
|
41
|
+
expected: isNot && useNotInLabel ? 'Expected [not]' : 'Expected',
|
|
42
|
+
received: isNot && useNotInLabel ? 'Received ' : 'Received'
|
|
43
|
+
};
|
|
44
|
+
const diffString = equals(actual, expected) ? `\
|
|
45
|
+
${label.expected}: ${printExpected(expected)}
|
|
46
|
+
${label.received}: ${printReceived(actual)}`
|
|
47
|
+
: printDiffOrStringify(expected, actual, label.expected, label.received, true);
|
|
54
48
|
if (message) {
|
|
55
49
|
message += '\n';
|
|
56
50
|
}
|
|
57
|
-
if (
|
|
58
|
-
|
|
51
|
+
if (expectedValueArgument2) {
|
|
52
|
+
expectedValueArgument2 = ` ${expectedValueArgument2}`;
|
|
59
53
|
}
|
|
60
|
-
const msg =
|
|
54
|
+
const msg = `\
|
|
55
|
+
${message}Expect ${subject} ${not(isNot)}to ${verb}${expectation}${expectedValueArgument2}${contain}
|
|
56
|
+
|
|
57
|
+
${diffString}`;
|
|
61
58
|
return msg;
|
|
62
59
|
};
|
|
63
|
-
export const enhanceErrorBe = (subject,
|
|
64
|
-
|
|
60
|
+
export const enhanceErrorBe = (subject, context, options) => {
|
|
61
|
+
const { isNot, verb, expectation } = context;
|
|
62
|
+
const expected = `${not(isNot)}${expectation}`;
|
|
63
|
+
const actual = `${not(!isNot)}${expectation}`;
|
|
64
|
+
return enhanceError(subject, expected, actual, { ...context, useNotInLabel: false }, verb, expectation, '', options);
|
|
65
65
|
};
|
|
66
66
|
export const numberError = (options = {}) => {
|
|
67
67
|
if (typeof options.eq === 'number') {
|
package/lib/utils.js
CHANGED
|
@@ -56,14 +56,14 @@ const waitUntil = async (condition, isNot = false, { wait = DEFAULT_OPTIONS.wait
|
|
|
56
56
|
}
|
|
57
57
|
};
|
|
58
58
|
async function executeCommandBe(received, command, options) {
|
|
59
|
-
const { isNot,
|
|
59
|
+
const { isNot, verb = 'be' } = this;
|
|
60
60
|
let el = await received?.getElement();
|
|
61
61
|
const pass = await waitUntil(async () => {
|
|
62
62
|
const result = await executeCommand.call(this, el, async (element) => ({ result: await command(element) }), options);
|
|
63
63
|
el = result.el;
|
|
64
64
|
return result.success;
|
|
65
65
|
}, isNot, options);
|
|
66
|
-
const message = enhanceErrorBe(el,
|
|
66
|
+
const message = enhanceErrorBe(el, { ...this, verb }, options);
|
|
67
67
|
return {
|
|
68
68
|
pass,
|
|
69
69
|
message: () => message,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expect-webdriverio",
|
|
3
|
-
"version": "5.6.
|
|
3
|
+
"version": "5.6.7",
|
|
4
4
|
"author": "Mykola Grybyk <mykola.grybyk@gmail.com>",
|
|
5
5
|
"description": "WebdriverIO Assertion Library",
|
|
6
6
|
"license": "MIT",
|
|
@@ -55,7 +55,9 @@
|
|
|
55
55
|
"build": "run-s clean compile",
|
|
56
56
|
"clean": "run-p clean:*",
|
|
57
57
|
"clean:build": "rimraf ./lib",
|
|
58
|
-
"compile": "
|
|
58
|
+
"compile": "run-s compile:*",
|
|
59
|
+
"compile:lib": "tsc --build tsconfig.build.json",
|
|
60
|
+
"compile:check": "if [ ! -f lib/index.js ] || [ $(find lib -type f | wc -l) -le 30 ]; then echo 'File structure under lib is broken'; exit 1; fi",
|
|
59
61
|
"tsc:root-types": "node types-checks-filter-out-node_modules.js",
|
|
60
62
|
"test": "run-s test:*",
|
|
61
63
|
"test:tsc": "tsc --project tsconfig.json --noEmit --rootDir .",
|
|
@@ -94,7 +96,7 @@
|
|
|
94
96
|
"eslint": "^9.39.2",
|
|
95
97
|
"husky": "^9.1.7",
|
|
96
98
|
"npm-run-all2": "^8.0.4",
|
|
97
|
-
"release-it": "^
|
|
99
|
+
"release-it": "^20.0.1",
|
|
98
100
|
"rimraf": "^6.1.2",
|
|
99
101
|
"shelljs": "^0.10.0",
|
|
100
102
|
"typescript": "^5.9.3",
|
|
@@ -320,7 +320,7 @@ interface WdioElementOrArrayMatchers<_R, ActualT = unknown> {
|
|
|
320
320
|
*/
|
|
321
321
|
toHaveHTML: FnWhenElementOrArrayLike<ActualT, (
|
|
322
322
|
html: string | RegExp | ExpectWebdriverIO.PartialMatcher<string> | Array<string | RegExp>,
|
|
323
|
-
options?: ExpectWebdriverIO.
|
|
323
|
+
options?: ExpectWebdriverIO.HTMLOptions
|
|
324
324
|
) => Promise<void>>
|
|
325
325
|
|
|
326
326
|
/**
|