expect-webdriverio 4.6.1 → 4.7.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.
package/lib/index.js CHANGED
@@ -1,7 +1,8 @@
1
- import { expect as expectLib } from 'expect';
1
+ import { jestExpect as expectLib } from '@jest/expect';
2
2
  import wdioMatchers from './matchers.js';
3
3
  import * as expectUtils from './utils.js';
4
4
  import { DEFAULT_OPTIONS } from './constants.js';
5
+ expectLib.setState({ suppressedErrors: [] });
5
6
  expectLib.extend({ ...wdioMatchers });
6
7
  export const expect = expectLib;
7
8
  export const matchers = wdioMatchers;
@@ -0,0 +1,9 @@
1
+ import { toMatchSnapshot as jestToMatchSnapshot, toMatchInlineSnapshot as jestToMatchInlineSnapshot } from 'jest-snapshot';
2
+ export async function toMatchElementSnapshot(el, ...args) {
3
+ this.expectation = this.expectation || 'matchElementSnapshot';
4
+ return jestToMatchSnapshot.call(this, await el.getHTML(), ...args);
5
+ }
6
+ export async function toMatchElementInlineSnapshot(el, ...args) {
7
+ this.expectation = this.expectation || 'matchElementInlineSnapshot';
8
+ return jestToMatchInlineSnapshot.call(this, await el.getHTML(), ...args);
9
+ }
@@ -0,0 +1,9 @@
1
+ import { toMatchSnapshot as jestToMatchSnapshot, toMatchInlineSnapshot as jestToMatchInlineSnapshot } from 'jest-snapshot';
2
+ export async function toMatchSnapshot(received, ...args) {
3
+ this.expectation = this.expectation || 'matchSnapshot';
4
+ return jestToMatchSnapshot.call(this, await received, ...args);
5
+ }
6
+ export async function toMatchInlineSnapshot(received, ...args) {
7
+ this.expectation = this.expectation || 'matchInlineSnapshot';
8
+ return jestToMatchInlineSnapshot.call(this, await received, ...args);
9
+ }
package/lib/matchers.js CHANGED
@@ -16,6 +16,7 @@ import * as toHaveClass from './matchers/element/toHaveClass.js';
16
16
  import * as toHaveHref from './matchers/element/toHaveHref.js';
17
17
  import * as toHaveId from './matchers/element/toHaveId.js';
18
18
  import * as toHaveSize from './matchers/element/toHaveSize.js';
19
+ import * as toMatchElementSnapshot from './matchers/element/toMatchElementSnapshot.js';
19
20
  import * as toHaveElementProperty from './matchers/element/toHaveElementProperty.js';
20
21
  import * as toHaveText from './matchers/element/toHaveText.js';
21
22
  import * as toHaveValue from './matchers/element/toHaveValue.js';
@@ -23,7 +24,9 @@ import * as toHaveStyle from './matchers/element/toHaveStyle.js';
23
24
  import * as toBeRequested from './matchers/mock/toBeRequested.js';
24
25
  import * as toBeRequestedTimes from './matchers/mock/toBeRequestedTimes.js';
25
26
  import * as toBeRequestedWith from './matchers/mock/toBeRequestedWith.js';
27
+ import * as toMatchSnapshot from './matchers/general/toMatchSnapshot.js';
26
28
  const matchers = {
29
+ ...toMatchSnapshot,
27
30
  ...toHaveClipboardText,
28
31
  ...toHaveTitle,
29
32
  ...toHaveUrl,
@@ -46,6 +49,7 @@ const matchers = {
46
49
  ...toHaveText,
47
50
  ...toHaveValue,
48
51
  ...toHaveStyle,
52
+ ...toMatchElementSnapshot,
49
53
  ...toBeRequested,
50
54
  ...toBeRequestedTimes,
51
55
  ...toBeRequestedWith,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expect-webdriverio",
3
- "version": "4.6.1",
3
+ "version": "4.7.1",
4
4
  "author": "Mykola Grybyk <mykola.grybyk@gmail.com>",
5
5
  "description": "WebdriverIO Assertion Library",
6
6
  "license": "MIT",
@@ -77,7 +77,7 @@
77
77
  "shelljs": "^0.8.5",
78
78
  "typescript": "^5.2.2",
79
79
  "vitest": "0.34.6",
80
- "webdriverio": "8.23.1"
80
+ "webdriverio": "8.24.6"
81
81
  },
82
82
  "optionalDependencies": {
83
83
  "@wdio/globals": "^8.23.1",
@@ -85,7 +85,8 @@
85
85
  "webdriverio": "^8.23.1"
86
86
  },
87
87
  "dependencies": {
88
- "expect": "^29.7.0",
88
+ "jest-snapshot": "^29.7.0",
89
+ "@jest/expect": "^29.7.0",
89
90
  "jest-matcher-utils": "^29.7.0",
90
91
  "lodash.isequal": "^4.5.0"
91
92
  }
@@ -1,7 +1,5 @@
1
1
  declare namespace ExpectWebdriverIO {
2
- function expect<T = unknown, R extends void | Promise<void> = void | Promise<void>>(
3
- actual: T
4
- ): Matchers<R, T>
2
+ const expect: ExpectWebdriverIO.Expect
5
3
  function setOptions(options: DefaultOptions): void
6
4
  function getConfig(): any
7
5
 
@@ -145,6 +143,29 @@ declare namespace ExpectWebdriverIO {
145
143
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
146
144
  interface Matchers<R, T> {
147
145
  // ===== $ or $$ =====
146
+ /**
147
+ * This ensures that element html value matches the most recent snapshot with property matchers.
148
+ */
149
+ toMatchElementSnapshot(hint?: string): R;
150
+ /**
151
+ * This ensures that element html matches the most recent snapshot.
152
+ */
153
+ toMatchElementSnapshot<U extends Record<keyof T, unknown>>(
154
+ propertyMatchers: Partial<U>,
155
+ hint?: string,
156
+ ): R;
157
+ /**
158
+ * This ensures that element html matches the most recent snapshot with property matchers.
159
+ */
160
+ toMatchElementInlineSnapshot(snapshot?: string): R;
161
+ /**
162
+ * This ensures that element html matches the most recent snapshot with property matchers.
163
+ */
164
+ toMatchElementInlineSnapshot<U extends Record<keyof T, unknown>>(
165
+ propertyMatchers: Partial<U>,
166
+ snapshot?: string,
167
+ ): R;
168
+
148
169
  /**
149
170
  * `WebdriverIO.Element` -> `isDisplayed`
150
171
  */
@@ -487,23 +508,23 @@ declare namespace ExpectWebdriverIO {
487
508
  method?: string | Array<string>
488
509
  statusCode?: number | Array<number>
489
510
  requestHeaders?:
490
- | Record<string, string>
491
- | ExpectWebdriverIO.PartialMatcher
492
- | ((headers: Record<string, string>) => boolean)
511
+ | Record<string, string>
512
+ | ExpectWebdriverIO.PartialMatcher
513
+ | ((headers: Record<string, string>) => boolean)
493
514
  responseHeaders?:
494
- | Record<string, string>
495
- | ExpectWebdriverIO.PartialMatcher
496
- | ((headers: Record<string, string>) => boolean)
515
+ | Record<string, string>
516
+ | ExpectWebdriverIO.PartialMatcher
517
+ | ((headers: Record<string, string>) => boolean)
497
518
  postData?:
498
- | string
499
- | ExpectWebdriverIO.JsonCompatible
500
- | ExpectWebdriverIO.PartialMatcher
501
- | ((r: string | undefined) => boolean)
519
+ | string
520
+ | ExpectWebdriverIO.JsonCompatible
521
+ | ExpectWebdriverIO.PartialMatcher
522
+ | ((r: string | undefined) => boolean)
502
523
  response?:
503
- | string
504
- | ExpectWebdriverIO.JsonCompatible
505
- | ExpectWebdriverIO.PartialMatcher
506
- | ((r: string) => boolean)
524
+ | string
525
+ | ExpectWebdriverIO.JsonCompatible
526
+ | ExpectWebdriverIO.PartialMatcher
527
+ | ((r: string) => boolean)
507
528
  }
508
529
 
509
530
  type jsonPrimitive = string | number | boolean | null
@@ -1,7 +1,5 @@
1
1
  /// <reference types="./standalone.js"/>
2
2
 
3
- declare const expect: ExpectWebdriverIO.Expect
4
-
5
3
  declare namespace NodeJS {
6
4
  interface Global {
7
5
  expect: ExpectWebdriverIO.Expect;
@@ -4,13 +4,13 @@ type ChainablePromiseElement = import('webdriverio').ChainablePromiseElement<Web
4
4
  type ChainablePromiseArray = import('webdriverio').ChainablePromiseArray<WebdriverIO.Element>
5
5
 
6
6
  declare namespace ExpectWebdriverIO {
7
- interface Matchers<R extends void | Promise<void>, T> extends Readonly<import('expect').Matchers<R>> {
7
+ interface Matchers<R extends void | Promise<void>, T> extends Readonly<import('expect').Matchers<R, T>>, Readonly<import('jest-snapshot').SnapshotMatchers<R, T>> {
8
8
  not: Matchers<R, T>
9
9
  resolves: Matchers<R, T>
10
10
  rejects: Matchers<R, T>
11
11
  }
12
12
 
13
- type Expect = {
13
+ type Expect = Readonly<import('@jest/expect').JestExpect> & {
14
14
  <T = unknown, R extends void | Promise<void> = void | Promise<void>>(actual: T): Matchers<R, T>
15
15
  extend(map: Record<string, Function>): void
16
16
  } & AsymmetricMatchers