expect-webdriverio 5.6.6 → 5.6.8

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/softExpect.js CHANGED
@@ -1,5 +1,6 @@
1
- import { expect, matchers } from './index.js';
1
+ import { expect } from './index.js';
2
2
  import { SoftAssertService } from './softAssert.js';
3
+ const isPossibleMatcher = (propName) => propName.startsWith('to') && propName.length > 2;
3
4
  const createSoftExpect = (actual) => {
4
5
  const softService = SoftAssertService.getInstance();
5
6
  return new Proxy({}, {
@@ -11,7 +12,7 @@ const createSoftExpect = (actual) => {
11
12
  if (propName === 'resolves' || propName === 'rejects') {
12
13
  return createSoftChainProxy(actual, propName, softService);
13
14
  }
14
- if (matchers.has(propName)) {
15
+ if (isPossibleMatcher(propName)) {
15
16
  return createSoftMatcher(actual, propName, softService);
16
17
  }
17
18
  return undefined;
@@ -20,28 +21,22 @@ const createSoftExpect = (actual) => {
20
21
  };
21
22
  const createSoftNotProxy = (actual, softService) => {
22
23
  return new Proxy({}, {
23
- get(target, prop) {
24
+ get(_target, prop) {
24
25
  const propName = String(prop);
25
- if (matchers.has(propName)) {
26
- return createSoftMatcher(actual, propName, softService, 'not');
27
- }
28
- return undefined;
26
+ return isPossibleMatcher(propName) ? createSoftMatcher(actual, propName, softService, 'not') : undefined;
29
27
  }
30
28
  });
31
29
  };
32
30
  const createSoftChainProxy = (actual, chainType, softService) => {
33
31
  return new Proxy({}, {
34
- get(target, prop) {
32
+ get(_target, prop) {
35
33
  const propName = String(prop);
36
- if (matchers.has(propName)) {
37
- return createSoftMatcher(actual, propName, softService, chainType);
38
- }
39
- return undefined;
34
+ return isPossibleMatcher(propName) ? createSoftMatcher(actual, propName, softService, chainType) : undefined;
40
35
  }
41
36
  });
42
37
  };
43
38
  const createSoftMatcher = (actual, matcherName, softService, prefix) => {
44
- return async (...args) => {
39
+ return (...args) => {
45
40
  try {
46
41
  let expectChain = expect(actual);
47
42
  if (prefix === 'not') {
@@ -53,16 +48,23 @@ const createSoftMatcher = (actual, matcherName, softService, prefix) => {
53
48
  else if (prefix === 'rejects') {
54
49
  expectChain = expectChain.rejects;
55
50
  }
56
- return await expectChain[matcherName](...args);
51
+ const assertionResult = expectChain[matcherName](...args);
52
+ if (assertionResult instanceof Promise) {
53
+ return assertionResult.catch((error) => handlingMatcherFailure(prefix, matcherName, softService, error));
54
+ }
55
+ return assertionResult;
57
56
  }
58
57
  catch (error) {
59
- const fullMatcherName = prefix ? `${prefix}.${matcherName}` : matcherName;
60
- softService.addFailure(error, fullMatcherName);
61
- return {
62
- pass: true,
63
- message: () => `Soft assertion failed: ${fullMatcherName}`
64
- };
58
+ return handlingMatcherFailure(prefix, matcherName, softService, error);
65
59
  }
66
60
  };
67
61
  };
62
+ function handlingMatcherFailure(prefix, matcherName, softService, error) {
63
+ const fullMatcherName = prefix ? `${prefix}.${matcherName}` : matcherName;
64
+ softService.addFailure(error, fullMatcherName);
65
+ return {
66
+ pass: true,
67
+ message: () => `Soft assertion failed: ${fullMatcherName}`
68
+ };
69
+ }
68
70
  export default createSoftExpect;
@@ -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
- export const not = (isNot) => {
34
- return `${isNot ? 'not ' : ''}`;
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
- let diffString = isNot && equals(actual, expected)
47
- ? `${EXPECTED_LABEL}: ${printExpected(expected)}\n${RECEIVED_LABEL}: ${printReceived(actual)}`
48
- : printDiffOrStringify(expected, actual, EXPECTED_LABEL, RECEIVED_LABEL, true);
49
- if (isNot) {
50
- diffString = diffString
51
- .replace(EXPECTED_LABEL, NOT_EXPECTED_LABEL)
52
- .replace(RECEIVED_LABEL, RECEIVED_LABEL + ' '.repeat(NOT_SUFFIX.length));
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 (arg2) {
58
- arg2 = ` ${arg2}`;
51
+ if (expectedValueArgument2) {
52
+ expectedValueArgument2 = ` ${expectedValueArgument2}`;
59
53
  }
60
- const msg = `${message}Expect ${subject} ${not(isNot)}to ${verb}${expectation}${arg2}${contain}\n\n${diffString}`;
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, pass, context, verb, expectation, options) => {
64
- return enhanceError(subject, not(context.isNot) + expectation, not(!pass) + expectation, context, verb, expectation, '', options);
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, expectation, verb = 'be' } = this;
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, pass, this, verb, expectation, options);
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.6",
3
+ "version": "5.6.8",
4
4
  "author": "Mykola Grybyk <mykola.grybyk@gmail.com>",
5
5
  "description": "WebdriverIO Assertion Library",
6
6
  "license": "MIT",
@@ -65,43 +65,42 @@
65
65
  "test:unit": "vitest --run",
66
66
  "test:types": "npm run ts && npm run tsc:root-types",
67
67
  "ts": "run-s ts:* ts:*:*",
68
- "ts:jest:@jest/global": "cd test-types/jest-@jest_global && tsc --project ./tsconfig.json",
69
- "ts:jest:@types-jest": "cd test-types/jest-@types_jest && tsc --project ./tsconfig.json",
70
- "ts:mocha": "cd test-types/mocha && tsc --project ./tsconfig.json",
71
- "ts:jasmine": "cd test-types/jasmine && tsc --project ./tsconfig.json",
72
- "ts:jasmine-async": "cd test-types/jasmine-async && tsc --project ./tsconfig.json",
68
+ "ts:jasmine": "cd test-types/jasmine && vitest --typecheck --typecheck.tsconfig ./tsconfig.json --run",
69
+ "ts:jasmine-global-expect-async": "cd test-types/jasmine-global-expect-async && vitest --typecheck --typecheck.tsconfig ./tsconfig.json --run",
70
+ "ts:jest:@types-jest": "cd test-types/jest-@types_jest && vitest --typecheck --typecheck.tsconfig ./tsconfig.json --run",
71
+ "ts:mocha": "cd test-types/mocha && vitest --typecheck --typecheck.tsconfig ./tsconfig.json --run",
73
72
  "checks:all": "npm run build && npm run compile && npm run tsc:root-types && npm run test && npm run ts",
74
73
  "watch": "npm run compile -- --watch",
75
74
  "prepare": "husky install",
76
- "playgrounds:setup": "for dir in playgrounds/*/; do cd \"$dir\" && npm install && cd ../..; done",
77
- "playgrounds:checks:all": "for dir in playgrounds/*/; do cd \"$dir\" && npm run checks:all && cd ../..; done",
78
- "playgrounds:snapshots:update": "cd playgrounds/mocha && npm run snapshots:update && cd ../jest && npm run snapshots:update && cd ../.."
75
+ "playgrounds:setup": "cd playgrounds && npm run setup",
76
+ "playgrounds:checks:all": "cd playgrounds && npm run checks:all",
77
+ "playgrounds:snapshots:update": "cd playgrounds && npm run snapshots:update"
79
78
  },
80
79
  "dependencies": {
81
- "@vitest/snapshot": "^4.0.16",
80
+ "@vitest/snapshot": "^4.1.7",
82
81
  "deep-eql": "^5.0.2",
83
- "expect": "^30.2.0",
84
- "jest-matcher-utils": "^30.2.0"
82
+ "expect": "^30.4.1",
83
+ "jest-matcher-utils": "^30.4.1"
85
84
  },
86
85
  "devDependencies": {
87
- "@types/debug": "^4.1.12",
88
- "@types/jasmine": "^5.1.8",
86
+ "@types/debug": "^4.1.13",
87
+ "@types/jasmine": "^5.1.15",
89
88
  "@types/jest": "^30.0.0",
90
- "@types/node": "^24.10.1",
89
+ "@types/node": "^24.12.4",
91
90
  "@types/mocha": "^10.0.10",
92
- "@jest/globals": "^30.2.0",
93
- "@vitest/coverage-v8": "^4.0.16",
94
- "@wdio/eslint": "^0.1.2",
95
- "@wdio/types": "^9.20.0",
96
- "eslint": "^9.39.2",
91
+ "@jest/globals": "^30.4.1",
92
+ "@vitest/coverage-v8": "^4.1.7",
93
+ "@wdio/eslint": "^0.1.3",
94
+ "@wdio/types": "^9.27.2",
95
+ "eslint": "^9.39.4",
97
96
  "husky": "^9.1.7",
98
- "npm-run-all2": "^8.0.4",
99
- "release-it": "^19.1.0",
100
- "rimraf": "^6.1.2",
97
+ "npm-run-all2": "^9.0.1",
98
+ "release-it": "^20.2.0",
99
+ "rimraf": "^6.1.3",
101
100
  "shelljs": "^0.10.0",
102
101
  "typescript": "^5.9.3",
103
- "vitest": "^4.0.16",
104
- "webdriverio": "^9.21.0"
102
+ "vitest": "^4.1.7",
103
+ "webdriverio": "^9.27.2"
105
104
  },
106
105
  "peerDependencies": {
107
106
  "@wdio/globals": "^9.0.0",