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
+26-21Lines changed: 26 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,22 +1,22 @@
1
1
# Expect-WebDriverIO Framework
2
2
3
-
Expect-WebDriverIO is inspired by [`expect`](https://www.npmjs.com/package/expect) but also extending it. Therefore we can exploit usually everything provided by the API of expect with some WebDriverIO touch.
3
+
Expect-WebDriverIO is inspired by [`expect`](https://www.npmjs.com/package/expect) but also extends it. Therefore, we can use everything provided by the expect API with some WebDriverIO enhancements.
4
4
- Note: Yes, this is a package of Jest but it is usable without Jest.
5
5
6
6
## Compatibility
7
7
8
-
We can pair `expect-webdriverio` with [Jest](https://jestjs.io/), [Mocha](https://mochajs.org/), [Jasmine](https://jasmine.github.io/).
9
-
- When an `expect` is defined globally, we usually overwrite it with the one of`expect-webdriverio` to have our defined assertions work out of the box.
8
+
We can pair `expect-webdriverio` with [Jest](https://jestjs.io/), [Mocha](https://mochajs.org/), and [Jasmine](https://jasmine.github.io/).
9
+
- When `expect` is defined globally, we usually overwrite it with the one from`expect-webdriverio` to have our defined assertions work out of the box.
10
10
11
11
### Jest
12
-
We can use `expect-webdriverio` with [Jest](https://jestjs.io/)with either the [`@jest/globals`](https://www.npmjs.com/package/@jest/globals) (preferred) or the [`@types/jest`](https://www.npmjs.com/package/@types/jest) (has global imports support)
12
+
We can use `expect-webdriverio` with [Jest](https://jestjs.io/)using either [`@jest/globals`](https://www.npmjs.com/package/@jest/globals) (preferred) or [`@types/jest`](https://www.npmjs.com/package/@types/jest) (has global imports support).
13
13
- Note: Jest maintainers do not support [`@types/jest`](https://www.npmjs.com/package/@types/jest). In case this library gets out of date or has problems, support might be dropped.
14
14
15
-
In each case, when used <u>**outside of [WDIO Testrunner](https://webdriver.io/docs/clioptions)**</u>, types are required to be added in your [`tsconfig.json`](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html)
16
-
- Note: With Jest the matchers `toMatchSnapshot` and `toMatchInlineSnapshot`were overloaded. To resolve correctly the types `expect-webdriverio/jest` must be last.
15
+
In each case, 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).
16
+
- Note: With Jest, the matchers `toMatchSnapshot` and `toMatchInlineSnapshot`are overloaded. To resolve the types correctly,`expect-webdriverio/jest` must be last.
17
17
18
18
#### With `@jest/globals`
19
-
When paired with [Jest](https://jestjs.io/) and the [`@jest/globals`](https://www.npmjs.com/package/@jest/globals), we should `import` the `expect`keyword from `expect-webdriverio`
19
+
When paired with [Jest](https://jestjs.io/) and [`@jest/globals`](https://www.npmjs.com/package/@jest/globals), we should `import` the `expect`function from `expect-webdriverio`.
Optionally, to not need`import { expect } from 'expect-webdriverio'` you can use the below
34
+
No `types`are expected in `tsconfig.json`.
35
+
Optionally, to avoid needing`import { expect } from 'expect-webdriverio'`, you can use the following:
36
36
```json
37
37
{
38
38
"compilerOptions": {
39
39
"types": ["expect-webdriverio/expect-global"]
40
40
}
41
41
}
42
-
```
42
+
```
43
+
##### Augmenting Jest's `expect`
44
+
Multiple attempts were made to augment `@jest/globals` to support `expect-webdriverio` matchers directly on Jest's `expect`. However, no namespace is available to augment it; therefore, only module augmentation can be used. This method does not allow adding matchers with the `extends` keyword; instead, they need to be added directly in the interface of the module declaration augmentation, which would create a lot of code duplication.
45
+
46
+
This [Jest issue](https://github.com/jestjs/jest/issues/12424) seems to target this problem, but it is still in progress.
47
+
43
48
44
49
#### With `@types/jest`
45
-
When paired with [Jest](https://jestjs.io/) and the [`@types/jest`](https://www.npmjs.com/package/@types/jest), no imports are required. Global ones are already defined correctly
50
+
When paired with [Jest](https://jestjs.io/) and [`@types/jest`](https://www.npmjs.com/package/@types/jest), no imports are required. Global types are already defined correctly.
46
51
47
52
```ts
48
53
describe('My tests', async () => {
@@ -67,10 +72,10 @@ Expected in `tsconfig.json`:
67
72
```
68
73
69
74
### Mocha
70
-
When paired with [Mocha](https://mochajs.org/), it can be used without (standalone) or with [`chai`](https://www.chaijs.com/) (or any other assertion library)
75
+
When paired with [Mocha](https://mochajs.org/), it can be used without (standalone) or with [`chai`](https://www.chaijs.com/) (or any other assertion library).
71
76
72
77
#### Standalone
73
-
No import is required, everything is set globally
78
+
No import is required; everything is set globally.
74
79
75
80
```ts
76
81
describe('My tests', async () => {
@@ -95,16 +100,16 @@ Expected in `tsconfig.json`:
95
100
```
96
101
97
102
#### Chai
98
-
`expect-webdriverio` can coexist with [Chai](https://www.chaijs.com/) assertion library, by importing both library explicitly.
99
-
See also this [documentation](https://webdriver.io/docs/assertion/#migrating-from-chai)
103
+
`expect-webdriverio` can coexist with the [Chai](https://www.chaijs.com/) assertion library by importing both libraries explicitly.
104
+
See also this [documentation](https://webdriver.io/docs/assertion/#migrating-from-chai).
100
105
101
106
### Jasmine
102
-
When paired with [Jasmine](https://jasmine.github.io/), [`@wdio/jasmine-framework`](https://www.npmjs.com/package/@wdio/jasmine-framework) is also required to have it configured correctly as it needs to force the `expect` to be `expectAsync` and also to register the wdio matchers with `addAsyncMatcher` since `expect-webdriverio` only supports the jest style `expect.extend` version.
107
+
When paired with [Jasmine](https://jasmine.github.io/), [`@wdio/jasmine-framework`](https://www.npmjs.com/package/@wdio/jasmine-framework) is also required to configure it correctly, as it needs to force `expect` to be `expectAsync` and also register the WDIO matchers with `addAsyncMatcher` since `expect-webdriverio` only supports the Jest-style `expect.extend` version.
103
108
104
-
The types `expect-webdriverio/jasmine`is still offers but subject to removal or to be moved into `@wdio/jasmine-framework`. The usage of `expectAsync` is also subject to future removal.
109
+
The types `expect-webdriverio/jasmine`are still offered but are subject to removal or being moved into `@wdio/jasmine-framework`. The usage of `expectAsync` is also subject to future removal.
105
110
106
111
#### Jasmine `expectAsync`
107
-
Since the above types augment the `AsyncMatcher` of `Jasmine` then with this library alone it looks like the below even though it is not runnable since the matchers are not registered
112
+
Since the above types augment the `AsyncMatcher` of Jasmine, with this library alone it looks like the following, even though it is not runnable since the matchers are not registered:
108
113
109
114
```ts
110
115
describe('My tests', async () => {
@@ -129,7 +134,7 @@ Expected in `tsconfig.json`:
129
134
```
130
135
131
136
#### `expect` of `expect-webdriverio`
132
-
It is preferable to use the `expect` from `expect-webdriverio` to guarantee future compatibility
137
+
It is preferable to use the `expect` from `expect-webdriverio` to guarantee future compatibility.
133
138
134
139
```ts
135
140
// Required if we do not force the 'expect-webdriverio' expect globally with `"expect-webdriverio/expect-global"`
@@ -150,14 +155,14 @@ Expected in `tsconfig.json`:
150
155
"compilerOptions": {
151
156
"types": [
152
157
"@types/jasmine",
153
-
"expect-webdriverio/expect-global", // Force expect to be the 'expect-webdriverio', to comment and use the import above if it conflict with Jasmine
158
+
"expect-webdriverio/expect-global", // Force expect to be the 'expect-webdriverio'; comment out and use the import above if it conflicts with Jasmine
154
159
]
155
160
}
156
161
}
157
162
```
158
163
159
164
#### Asymmetric matcher
160
-
Asymmetric matcher has limited support, even though `jasmine.stringContaining` has no error it is potentially not working even with `@wdio/jasmine-framework`, but the below should:
165
+
Asymmetric matchers have limited support. Even though `jasmine.stringContaining` has no error, it is potentially not working even with `@wdio/jasmine-framework`, but the below should work:
0 commit comments