expect-webdriverio 5.2.1 → 5.3.0

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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expect-webdriverio",
3
- "version": "5.2.1",
3
+ "version": "5.3.0",
4
4
  "author": "Mykola Grybyk <mykola.grybyk@gmail.com>",
5
5
  "description": "WebdriverIO Assertion Library",
6
6
  "license": "MIT",
@@ -58,29 +58,29 @@
58
58
  "prepare": "husky install"
59
59
  },
60
60
  "dependencies": {
61
- "@vitest/snapshot": "^3.2.0",
61
+ "@vitest/snapshot": "^3.2.1",
62
62
  "expect": "^29.7.0",
63
63
  "jest-matcher-utils": "^29.7.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.12",
68
+ "@types/jest": "^29.5.14",
69
69
  "@types/lodash.isequal": "^4.5.8",
70
- "@types/node": "^22.9.0",
71
- "@vitest/coverage-v8": "^3.0.5",
72
- "@wdio/eslint": "^0.1.0",
73
- "@wdio/types": "^9.9.0",
74
- "c8": "^10.1.2",
75
- "eslint": "^9.15.0",
76
- "husky": "^9.1.5",
77
- "npm-run-all2": "^7.0.1",
78
- "release-it": "^19.0.1",
70
+ "@types/node": "^22.15.29",
71
+ "@vitest/coverage-v8": "^3.2.1",
72
+ "@wdio/eslint": "^0.1.1",
73
+ "@wdio/types": "^9.15.0",
74
+ "c8": "^10.1.3",
75
+ "eslint": "^9.28.0",
76
+ "husky": "^9.1.7",
77
+ "npm-run-all2": "^8.0.4",
78
+ "release-it": "^19.0.3",
79
79
  "rimraf": "^6.0.1",
80
- "shelljs": "^0.9.1",
81
- "typescript": "^5.5.4",
82
- "vitest": "^3.0.4",
83
- "webdriverio": "^9.2.11"
80
+ "shelljs": "^0.10.0",
81
+ "typescript": "^5.8.3",
82
+ "vitest": "^3.2.1",
83
+ "webdriverio": "^9.15.0"
84
84
  },
85
85
  "peerDependencies": {
86
86
  "@wdio/globals": "^9.0.0",
@@ -1,16 +1,24 @@
1
+ type ServiceInstance = import('@wdio/types').Services.ServiceInstance;
2
+ type Test = import('@wdio/types').Frameworks.Test;
3
+ type TestResult = import('@wdio/types').Frameworks.TestResult;
4
+ type PickleStep = import('@wdio/types').Frameworks.PickleStep;
5
+ type Scenario = import('@wdio/types').Frameworks.Scenario;
6
+ type SnapshotResult = import('@vitest/snapshot').SnapshotResult;
7
+ type SnapshotUpdateState = import('@vitest/snapshot').SnapshotUpdateState;
8
+
1
9
  declare namespace ExpectWebdriverIO {
2
10
  const expect: ExpectWebdriverIO.Expect
3
11
  function setOptions(options: DefaultOptions): void
4
12
  function getConfig(): any
5
13
 
6
14
  interface SnapshotServiceArgs {
7
- updateState?: import('@vitest/snapshot').SnapshotUpdateState
15
+ updateState?: SnapshotUpdateState
8
16
  resolveSnapshotPath?: (path: string, extension: string) => string
9
17
  }
10
18
 
11
19
  class SnapshotService {
12
- static initiate(options: SnapshotServiceArgs): import('@wdio/types').Services.ServiceInstance & {
13
- results: import('@vitest/snapshot').SnapshotResult[]
20
+ static initiate(options: SnapshotServiceArgs): ServiceInstance & {
21
+ results: SnapshotResult[]
14
22
  }
15
23
  }
16
24
 
@@ -35,12 +43,12 @@ declare namespace ExpectWebdriverIO {
35
43
  autoAssertOnTestEnd?: boolean;
36
44
  }
37
45
 
38
- class SoftAssertionService implements import('@wdio/types').Services.ServiceInstance {
46
+ class SoftAssertionService implements ServiceInstance {
39
47
  constructor(serviceOptions?: SoftAssertionServiceOptions, capabilities?: any, config?: any);
40
- beforeTest(test: import('@wdio/types').Frameworks.Test): void;
41
- beforeStep(step: import('@wdio/types').Frameworks.PickleStep, scenario: import('@wdio/types').Frameworks.Scenario): void;
42
- afterTest(test: import('@wdio/types').Frameworks.Test, context: any, result: import('@wdio/types').Frameworks.TestResult): void;
43
- afterStep(step: import('@wdio/types').Frameworks.PickleStep, scenario: import('@wdio/types').Frameworks.Scenario, result: { passed: boolean, error?: Error }): void;
48
+ beforeTest(test: Test): void;
49
+ beforeStep(step: PickleStep, scenario: Scenario): void;
50
+ afterTest(test: Test, context: any, result: TestResult): void;
51
+ afterStep(step: PickleStep, scenario: Scenario, result: { passed: boolean, error?: Error }): void;
44
52
  }
45
53
 
46
54
  interface AssertionResult {