You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/Framework.md
+14-3Lines changed: 14 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ We can pair `expect-webdriverio` with [Jest](https://jestjs.io/), [Mocha](https:
9
9
10
10
It is highly recommended to use it with a [WDIO Testrunner](https://webdriver.io/docs/clioptions) which provides additional auto-configuration for a plug-and-play experience.
11
11
12
-
When used <u>**outside of [WDIO Testrunner](https://webdriver.io/docs/clioptions)**</u>, types need to be added to your [`tsconfig.json`](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html).
12
+
When used <u>**outside of [WDIO Testrunner](https://webdriver.io/docs/clioptions)**</u>, types need to be added to your [`tsconfig.json`](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html), and some additional configuration for WDIO matchers, soft assertions, and snapshot service is required.
13
13
14
14
### Jest
15
15
We can use `expect-webdriverio` with [Jest](https://jestjs.io/) using [`@jest/globals`](https://www.npmjs.com/package/@jest/globals) alone (preferred) and optionally [`@types/jest`](https://www.npmjs.com/package/@types/jest) (which has global ambient support).
@@ -50,15 +50,26 @@ This [Jest issue](https://github.com/jestjs/jest/issues/12424) seems to target t
50
50
#### With `@types/jest`
51
51
When also paired with [`@types/jest`](https://www.npmjs.com/package/@types/jest), no imports are required. Global ambient types are already defined correctly and you can simply use Jest's `expect` directly.
52
52
53
-
If you are NOT using WDIO Testrunner, it may be required to correctly register the WDIO matchers on Jest's `expect` as shown below:
53
+
If you are NOT using WDIO Testrunner, some prerequisite configuration is required.
54
+
55
+
Option 1: Replace the expect globally with the `expect-webdriverio` one:
54
56
```ts
57
+
import { expect } from"expect-webdriverio";
58
+
(globalThisasany).expect=expect;
59
+
```
60
+
61
+
Option 2: Reconfigure Jest's expect with the custom matchers and the soft assertion:
62
+
```ts
63
+
// Configure the custom matchers:
55
64
import { expect } from"@jest/globals";
56
65
import { matchers } from"expect-webdriverio";
57
66
58
67
beforeAll(async () => {
59
-
expect.extend(matchers);
68
+
expect.extend(matchersasRecord<string, any>);
60
69
});
61
70
```
71
+
For the soft assertion, it needs to expose the `createSoftExpect` first.
72
+
62
73
63
74
As shown below, no imports are required and we can use WDIO matchers directly on Jest's `expect`:
0 commit comments