Skip to content

Commit 7e58f77

Browse files
committed
Add documentation on required configuration
1 parent 61f2048 commit 7e58f77

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

docs/Framework.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ We can pair `expect-webdriverio` with [Jest](https://jestjs.io/), [Mocha](https:
99

1010
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.
1111

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.
1313

1414
### Jest
1515
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
5050
#### With `@types/jest`
5151
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.
5252

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:
5456
```ts
57+
import { expect } from "expect-webdriverio";
58+
(globalThis as any).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:
5564
import { expect } from "@jest/globals";
5665
import { matchers } from "expect-webdriverio";
5766

5867
beforeAll(async () => {
59-
expect.extend(matchers);
68+
expect.extend(matchers as Record<string, any>);
6069
});
6170
```
71+
For the soft assertion, it needs to expose the `createSoftExpect` first.
72+
6273

6374
As shown below, no imports are required and we can use WDIO matchers directly on Jest's `expect`:
6475
```ts

0 commit comments

Comments
 (0)