expect-webdriverio 5.6.7 → 5.6.9

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/jest.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  /// <reference types="./types/expect-webdriverio.d.ts"/>
2
2
 
3
3
  /**
4
- * Augment the Jest namespace to include the matchers from expect-webdriverio.
5
- * When Jest Library is used, it specifies `expect-webdriverio/jest` for this file in the tsconfig.json's types.
4
+ * Augment the Jest namespace to include the WebDriverIO custom matchers only.
5
+ * When Jest Library is used, specify `expect-webdriverio/jest` for this file in the tsconfig.json's types.
6
6
  */
7
7
 
8
8
  declare namespace jest {
@@ -13,7 +13,7 @@ declare namespace jest {
13
13
  * Below are overloaded Jest's matchers not part of `expect` but of `jest-snapshot`.
14
14
  * @see https://github.com/jestjs/jest/blob/73dbef5d2d3195a1e55fb254c54cce70d3036252/packages/jest-snapshot/src/types.ts#L37
15
15
  *
16
- * Note: We need to define them below so that they are correctly typed overloaded.
16
+ * Note: We need to define them below so that they are correctly overloaded.
17
17
  * Else even when extending `WdioJestOverloadedMatchers` we have typing errors.
18
18
  */
19
19
 
@@ -21,17 +21,17 @@ declare namespace jest {
21
21
  * snapshot matcher
22
22
  * @param label optional snapshot label
23
23
  */
24
- toMatchSnapshot(label?: string): T extends WdioPromiseLike ? Promise<void> : void;
24
+ toMatchSnapshot(label?: string): T extends WdioElementOrPromiseLike ? Promise<void> : R;
25
25
 
26
26
  /**
27
27
  * inline snapshot matcher
28
28
  * @param snapshot snapshot string (autogenerated if not specified)
29
29
  * @param label optional snapshot label
30
30
  */
31
- toMatchInlineSnapshot(snapshot?: string, label?: string): T extends WdioPromiseLike ? Promise<void> : void;
31
+ toMatchInlineSnapshot(snapshot?: string, label?: string): T extends WdioElementOrPromiseLike ? Promise<void> : R;
32
32
  }
33
33
 
34
34
  interface Expect extends ExpectWebdriverIO.Expect {}
35
35
 
36
36
  interface InverseAsymmetricMatchers extends ExpectWebdriverIO.AsymmetricMatchers {}
37
- }
37
+ }
package/lib/index.js CHANGED
@@ -3,6 +3,7 @@ import * as wdioMatchers from './matchers.js';
3
3
  import { DEFAULT_OPTIONS, defaultOptionsList } from './constants.js';
4
4
  import createSoftExpect from './softExpect.js';
5
5
  import { SoftAssertService } from './softAssert.js';
6
+ export const wdioCustomMatchers = {};
6
7
  export const matchers = new Map();
7
8
  const filteredMatchers = {};
8
9
  const extend = expectLib.extend;
@@ -15,7 +16,10 @@ expectLib.extend = (m) => {
15
16
  if (!m || typeof m !== 'object') {
16
17
  return;
17
18
  }
18
- Object.entries(m).forEach(([name, matcher]) => matchers.set(name, matcher));
19
+ Object.entries(m).forEach(([name, matcher]) => {
20
+ wdioCustomMatchers[name] = matcher;
21
+ matchers.set(name, matcher);
22
+ });
19
23
  return extend(m);
20
24
  };
21
25
  expectLib.extend(filteredMatchers);
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expect-webdriverio",
3
- "version": "5.6.7",
3
+ "version": "5.6.9",
4
4
  "author": "Mykola Grybyk <mykola.grybyk@gmail.com>",
5
5
  "description": "WebdriverIO Assertion Library",
6
6
  "license": "MIT",
@@ -65,43 +65,41 @@
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
- "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 ../.."
74
+ "prepare": "husky",
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": "^20.0.1",
100
- "rimraf": "^6.1.2",
101
- "shelljs": "^0.10.0",
97
+ "npm-run-all2": "^9.0.1",
98
+ "release-it": "^20.2.0",
99
+ "rimraf": "^6.1.3",
102
100
  "typescript": "^5.9.3",
103
- "vitest": "^4.0.16",
104
- "webdriverio": "^9.21.0"
101
+ "vitest": "^4.1.7",
102
+ "webdriverio": "^9.27.2"
105
103
  },
106
104
  "peerDependencies": {
107
105
  "@wdio/globals": "^9.0.0",
@@ -12,4 +12,4 @@ declare namespace NodeJS {
12
12
  interface Global {
13
13
  expect: ExpectWebdriverIO.Expect
14
14
  }
15
- }
15
+ }
@@ -20,6 +20,7 @@ type ExpectLibSyncExpectationResult = import('expect').SyncExpectationResult
20
20
  type ExpectLibAsyncExpectationResult = import('expect').AsyncExpectationResult
21
21
  type ExpectLibExpectationResult = import('expect').ExpectationResult
22
22
  type ExpectLibMatcherContext = import('expect').MatcherContext
23
+ type MatchersObject = Parameters<typeof import('expect').expect.extend>[0]
23
24
 
24
25
  // Extracted from the expect library, this is the type of the matcher function used in the expect library.
25
26
  type RawMatcherFn<Context extends ExpectLibMatcherContext = ExpectLibMatcherContext> = {
@@ -31,6 +32,7 @@ type RawMatcherFn<Context extends ExpectLibMatcherContext = ExpectLibMatcherCont
31
32
  * Real Promise and wdio chainable promise types.
32
33
  */
33
34
  type WdioPromiseLike<T = unknown> = PromiseLike<T> | ChainablePromiseElement | ChainablePromiseArray
35
+ type WdioElementOrPromiseLike<T = unknown> = WdioPromiseLike<T> | WebdriverIO.Element
34
36
  type ElementPromise = Promise<WebdriverIO.Element>
35
37
  type ElementArrayPromise = Promise<WebdriverIO.ElementArray>
36
38
 
@@ -201,7 +203,7 @@ interface WdioElementOrArrayMatchers<_R, ActualT = unknown> {
201
203
  ActualT,
202
204
  (
203
205
  property: string,
204
- value?: string | RegExp | WdioAsymmetricMatcher<string> | null,
206
+ value?: string | RegExp | ExpectWebdriverIO.PartialMatcher<string> | null,
205
207
  options?: ExpectWebdriverIO.StringOptions,
206
208
  ) => Promise<void>
207
209
  >
@@ -396,18 +398,18 @@ interface WdioElementArrayOnlyMatchers<_R, ActualT = unknown> {
396
398
  * Therefore, they also need to be redefined in the jest.d.ts file so correctly overload the matchers from the Jest namespace.
397
399
  * @see jest.d.ts
398
400
  */
399
- interface WdioJestOverloadedMatchers<_R, ActualT> {
401
+ interface WdioJestOverloadedMatchers<R, ActualT> {
400
402
  /**
401
403
  * snapshot matcher
402
404
  * @param label optional snapshot label
403
405
  */
404
- toMatchSnapshot(label?: string): ActualT extends WdioPromiseLike ? Promise<void> : void;
406
+ toMatchSnapshot(label?: string): ActualT extends WdioElementOrPromiseLike ? Promise<void> : R
405
407
  /**
406
408
  * inline snapshot matcher
407
409
  * @param snapshot snapshot string (autogenerated if not specified)
408
410
  * @param label optional snapshot label
409
411
  */
410
- toMatchInlineSnapshot(snapshot?: string, label?: string): ActualT extends WdioPromiseLike ? Promise<void> : void;
412
+ toMatchInlineSnapshot(snapshot?: string, label?: string): ActualT extends WdioElementOrPromiseLike ? Promise<void> : R
411
413
  }
412
414
 
413
415
  /**
@@ -583,17 +585,25 @@ declare namespace ExpectWebdriverIO {
583
585
  type AsyncAssertionResult = ExpectLibAsyncExpectationResult
584
586
 
585
587
  /**
586
- * Used by the wdio main project to configure the matchers in the runner when using Jasmine or Jest.
588
+ * Used to register wdio custom matcher like the Jest's `expect.extend`. Wdio main project configure the matchers in the runner when using Jasmine.
589
+ * Contains only the custom matchers from wdio, and not the ones from the expect library, to avoid any conflict with the matchers from the expect library when using Jasmine or Jest.
590
+ * Map to src/index.ts#wdioCustomMatchers
591
+ *
587
592
  * Equivalent as `MatchersObject` from the expect library.
588
593
  * @see https://github.com/jestjs/jest/blob/fd3d6cf9fe416b549a74b6577e5e1ea1130e3659/packages/expect/src/types.ts#L43C13-L43C27
589
594
  */
595
+ const wdioCustomMatchers: MatchersObject
596
+
597
+ /**
598
+ * @deprecated use `wdioCustomMatchers` instead
599
+ */
590
600
  const matchers: Map<string, RawMatcherFn>
591
601
 
592
602
  interface AssertionHookParams {
593
603
  /**
594
604
  * name of the matcher, e.g. `toHaveText` or `toBeClickable`
595
605
  */
596
- matcherName: keyof Matchers<void, unknown>,
606
+ matcherName: keyof Matchers<void, unknown>
597
607
  /**
598
608
  * Value that the user has passed in
599
609
  *