expect-webdriverio 5.6.8 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expect-webdriverio",
3
- "version": "5.6.8",
3
+ "version": "5.6.9",
4
4
  "author": "Mykola Grybyk <mykola.grybyk@gmail.com>",
5
5
  "description": "WebdriverIO Assertion Library",
6
6
  "license": "MIT",
@@ -71,7 +71,7 @@
71
71
  "ts:mocha": "cd test-types/mocha && vitest --typecheck --typecheck.tsconfig ./tsconfig.json --run",
72
72
  "checks:all": "npm run build && npm run compile && npm run tsc:root-types && npm run test && npm run ts",
73
73
  "watch": "npm run compile -- --watch",
74
- "prepare": "husky install",
74
+ "prepare": "husky",
75
75
  "playgrounds:setup": "cd playgrounds && npm run setup",
76
76
  "playgrounds:checks:all": "cd playgrounds && npm run checks:all",
77
77
  "playgrounds:snapshots:update": "cd playgrounds && npm run snapshots:update"
@@ -97,7 +97,6 @@
97
97
  "npm-run-all2": "^9.0.1",
98
98
  "release-it": "^20.2.0",
99
99
  "rimraf": "^6.1.3",
100
- "shelljs": "^0.10.0",
101
100
  "typescript": "^5.9.3",
102
101
  "vitest": "^4.1.7",
103
102
  "webdriverio": "^9.27.2"
@@ -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
  *