expect-webdriverio 5.2.2 → 5.3.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.
@@ -1,10 +1,10 @@
1
1
  import { DEFAULT_OPTIONS } from '../../constants.js';
2
- import { enhanceError, executeCommand, waitUntil, wrapExpectedWithArray } from '../../utils.js';
3
- async function condition(el, height) {
2
+ import { compareNumbers, enhanceError, executeCommand, numberError, waitUntil, } from '../../utils.js';
3
+ async function condition(el, height, options) {
4
4
  const actualHeight = await el.getSize('height');
5
5
  return {
6
- value: actualHeight,
7
- result: actualHeight === height,
6
+ result: compareNumbers(actualHeight, options),
7
+ value: actualHeight
8
8
  };
9
9
  }
10
10
  export async function toHaveHeight(received, expectedValue, options = DEFAULT_OPTIONS) {
@@ -15,15 +15,26 @@ export async function toHaveHeight(received, expectedValue, options = DEFAULT_OP
15
15
  expectedValue,
16
16
  options,
17
17
  });
18
+ let numberOptions;
19
+ if (typeof expectedValue === 'number') {
20
+ numberOptions = { eq: expectedValue };
21
+ }
22
+ else if (!expectedValue || (typeof expectedValue.eq !== 'number' && typeof expectedValue.gte !== 'number' && typeof expectedValue.lte !== 'number')) {
23
+ throw new Error('Invalid params passed to toHaveHeight.');
24
+ }
25
+ else {
26
+ numberOptions = expectedValue;
27
+ }
18
28
  let el = await received?.getElement();
19
29
  let actualHeight;
20
30
  const pass = await waitUntil(async () => {
21
- const result = await executeCommand.call(this, el, condition, options, [expectedValue, options]);
31
+ const result = await executeCommand.call(this, el, condition, numberOptions, [expectedValue, numberOptions]);
22
32
  el = result.el;
23
33
  actualHeight = result.values;
24
34
  return result.success;
25
- }, isNot, options);
26
- const message = enhanceError(el, wrapExpectedWithArray(el, actualHeight, expectedValue), actualHeight, this, verb, expectation, '', options);
35
+ }, isNot, { ...numberOptions, ...options });
36
+ const error = numberError(numberOptions);
37
+ const message = enhanceError(el, error, actualHeight, this, verb, expectation, '', options);
27
38
  const result = {
28
39
  pass,
29
40
  message: () => message
@@ -1,10 +1,10 @@
1
1
  import { DEFAULT_OPTIONS } from '../../constants.js';
2
- import { enhanceError, executeCommand, waitUntil, wrapExpectedWithArray } from '../../utils.js';
3
- async function condition(el, width) {
2
+ import { compareNumbers, enhanceError, executeCommand, numberError, waitUntil, } from '../../utils.js';
3
+ async function condition(el, width, options) {
4
4
  const actualWidth = await el.getSize('width');
5
5
  return {
6
- value: actualWidth,
7
- result: actualWidth === width,
6
+ result: compareNumbers(actualWidth, options),
7
+ value: actualWidth
8
8
  };
9
9
  }
10
10
  export async function toHaveWidth(received, expectedValue, options = DEFAULT_OPTIONS) {
@@ -15,15 +15,26 @@ export async function toHaveWidth(received, expectedValue, options = DEFAULT_OPT
15
15
  expectedValue,
16
16
  options,
17
17
  });
18
+ let numberOptions;
19
+ if (typeof expectedValue === 'number') {
20
+ numberOptions = { eq: expectedValue };
21
+ }
22
+ else if (!expectedValue || (typeof expectedValue.eq !== 'number' && typeof expectedValue.gte !== 'number' && typeof expectedValue.lte !== 'number')) {
23
+ throw new Error('Invalid params passed to toHaveHeight.');
24
+ }
25
+ else {
26
+ numberOptions = expectedValue;
27
+ }
18
28
  let el = await received?.getElement();
19
29
  let actualWidth;
20
30
  const pass = await waitUntil(async () => {
21
- const result = await executeCommand.call(this, el, condition, options, [expectedValue, options]);
31
+ const result = await executeCommand.call(this, el, condition, numberOptions, [expectedValue, numberOptions]);
22
32
  el = result.el;
23
33
  actualWidth = result.values;
24
34
  return result.success;
25
- }, isNot, options);
26
- const message = enhanceError(el, wrapExpectedWithArray(el, actualWidth, expectedValue), actualWidth, this, verb, expectation, '', options);
35
+ }, isNot, { ...numberOptions, ...options });
36
+ const error = numberError(numberOptions);
37
+ const message = enhanceError(el, error, actualWidth, this, verb, expectation, '', options);
27
38
  const result = {
28
39
  pass,
29
40
  message: () => message
@@ -1,5 +1,6 @@
1
1
  import path from 'node:path';
2
2
  import { expect } from 'expect';
3
+ import { stripSnapshotIndentation } from '@vitest/snapshot';
3
4
  import { SnapshotService } from '../snapshot.js';
4
5
  function returnSnapshotError(snapshotError) {
5
6
  try {
@@ -73,9 +74,16 @@ export function toMatchInlineSnapshot(received, inlineSnapshot, message) {
73
74
  ...stack.slice(3)
74
75
  ].join('\n');
75
76
  }
76
- error.stack = error.stack?.split('\n').filter((line) => (line.includes('__INLINE_SNAPSHOT__') ||
77
+ const trace = error.stack?.split('\n').filter((line) => (line.includes('__INLINE_SNAPSHOT__') ||
77
78
  !(line.includes('__EXTERNAL_MATCHER_TRAP__') ||
78
- line.includes(`expect-webdriverio${path.sep}lib${path.sep}matchers${path.sep}snapshot.js:`)))).join('\n');
79
+ line.includes(`expect-webdriverio${path.sep}lib${path.sep}matchers${path.sep}snapshot.js:`)))) || [];
80
+ if (process.env.WDIO_INTERNAL_TEST) {
81
+ trace.splice(2, 1);
82
+ }
83
+ if (inlineSnapshot) {
84
+ inlineSnapshot = stripSnapshotIndentation(inlineSnapshot);
85
+ }
86
+ error.stack = trace.join('\n');
79
87
  return toMatchSnapshotHelper(received, message, {
80
88
  inlineSnapshot,
81
89
  error
package/lib/snapshot.js CHANGED
@@ -43,9 +43,15 @@ export class SnapshotService {
43
43
  : options?.updateState
44
44
  ? options.updateState
45
45
  : 'new';
46
+ const snapshotFormatConfig = options?.snapshotFormat ? {
47
+ printBasicPrototype: false,
48
+ escapeString: false,
49
+ ...options.snapshotFormat
50
+ } : undefined;
46
51
  __classPrivateFieldSet(this, _SnapshotService_options, {
47
52
  updateSnapshot,
48
- snapshotEnvironment: new WebdriverIOSnapshotEnvironment(options?.resolveSnapshotPath)
53
+ snapshotEnvironment: new WebdriverIOSnapshotEnvironment(options?.resolveSnapshotPath),
54
+ ...(snapshotFormatConfig && { snapshotFormat: snapshotFormatConfig })
49
55
  }, "f");
50
56
  }
51
57
  get currentFilePath() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expect-webdriverio",
3
- "version": "5.2.2",
3
+ "version": "5.3.1",
4
4
  "author": "Mykola Grybyk <mykola.grybyk@gmail.com>",
5
5
  "description": "WebdriverIO Assertion Library",
6
6
  "license": "MIT",
@@ -58,28 +58,28 @@
58
58
  "prepare": "husky install"
59
59
  },
60
60
  "dependencies": {
61
- "@vitest/snapshot": "^3.2.1",
62
- "expect": "^29.7.0",
63
- "jest-matcher-utils": "^29.7.0",
61
+ "@vitest/snapshot": "^3.2.4",
62
+ "expect": "^30.0.0",
63
+ "jest-matcher-utils": "^30.0.0",
64
64
  "lodash.isequal": "^4.5.0"
65
65
  },
66
66
  "devDependencies": {
67
67
  "@types/debug": "^4.1.12",
68
- "@types/jest": "^29.5.14",
68
+ "@types/jest": "^30.0.0",
69
69
  "@types/lodash.isequal": "^4.5.8",
70
- "@types/node": "^22.15.29",
71
- "@vitest/coverage-v8": "^3.2.1",
70
+ "@types/node": "^24.0.3",
71
+ "@vitest/coverage-v8": "^3.2.4",
72
72
  "@wdio/eslint": "^0.1.1",
73
73
  "@wdio/types": "^9.15.0",
74
74
  "c8": "^10.1.3",
75
- "eslint": "^9.28.0",
75
+ "eslint": "^9.29.0",
76
76
  "husky": "^9.1.7",
77
77
  "npm-run-all2": "^8.0.4",
78
78
  "release-it": "^19.0.3",
79
79
  "rimraf": "^6.0.1",
80
80
  "shelljs": "^0.10.0",
81
81
  "typescript": "^5.8.3",
82
- "vitest": "^3.2.1",
82
+ "vitest": "^3.2.4",
83
83
  "webdriverio": "^9.15.0"
84
84
  },
85
85
  "peerDependencies": {