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
fix: Jasmine augmentation withContext and add Playgrounds for Jasmine, Jest & Mocha (#2010)
* Add mocha playgrounds
- expect-wdio releases breaks easily other integration since we just test with unit tests
- Adding playground will help testing further before releasing and also helps troubleshooting existing problem inside the project
* Add jasmine & jest playgrounds
* Code reviews
* Add visual snapshot to playgrounds
* Document Jasmine quicks + fix type + Add withContext problem example
* Remove soft from Jasmine since it useless
* Add eslint and no-floating-promise to playgrounds
* Fix Jasmine withContext + use project global instead of wdio one
* Use proper folder for visual test + review jasmine docs quicks
* Review
* fix temp missing ignore
* Have stable e2e
* Review doc
* More concise doc
* Remove snapshot from Jasmine, update snapshot for others
Copy file name to clipboardExpand all lines: docs/API.md
+88-6Lines changed: 88 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -63,7 +63,7 @@ expect.clearSoftFailures();
63
63
64
64
### Integration with Test Frameworks
65
65
66
-
The soft assertions feature integrates with WebdriverIO's test runner automatically. By default, it will report all soft assertion failures at the end of each test (Mocha/Jasmine) or step (Cucumber).
66
+
The soft assertions feature integrates with WebdriverIO's test runner automatically. By default, it will report all soft assertion failures at the end of each test (Mocha) or step (Cucumber).
67
67
68
68
To use with WebdriverIO, add the SoftAssertionService to your services list:
69
69
@@ -75,7 +75,7 @@ export const config = {
75
75
// ...
76
76
services: [
77
77
// ...other services
78
-
[SoftAssertionService]
78
+
[SoftAssertionService, {}]
79
79
],
80
80
// ...
81
81
}
@@ -113,8 +113,7 @@ This is useful if you want full control over when soft assertions are verified o
113
113
114
114
### Known limitations
115
115
116
-
For Jasmine, using `wdio-jasmine-framework` will give a better plug-and-play experiences, else without it, the soft assertion service and custom matchers might not work/be registered correctly.
117
-
Moreover, if Jasmine augmentation is used, the soft assertion function are not exposed in the typing, but could still work depending of your configuration. See [this issue](https://github.com/webdriverio/expect-webdriverio/issues/1893) for more details.
116
+
The soft assertions service is not supported under Jasmine (e.g. `@wdio/jasmine-framework`) using the global import because Jasmine is already designed to provide similar behavior out of the box.
In addition to the `expect-webdriverio` matchers you can use builtin Jest's [expect](https://jestjs.io/docs/expect) assertions or [expect/expectAsync](https://jasmine.github.io/api/edge/global.html#expect) for Jasmine.
907
+
In addition to the WebdriverIO matchers, `expect-webdriverio` also provides basic matchers from Jest's [expect](https://jestjs.io/docs/expect) library.
For Jasmine, see the official documentation for [expect/expectAsync](https://jasmine.github.io/api/edge/global.html#expect), [matchers](https://jasmine.github.io/tutorials/your_first_suite#section-Matchers), and [async-matchers](https://jasmine.github.io/api/edge/async-matchers.html).
969
+
970
+
**Note:**
971
+
- With the global import in @wdio/jasmine-framework, only WebdriverIO custom matchers are registered on expectAsync (assigned to global expect), so all matchers are always async, even those that are normally synchronous.
972
+
- Default matchers are still available if you import `expect` directly from `expect-webdriverio` instead of using the global.
Copy file name to clipboardExpand all lines: docs/Framework.md
+8-3Lines changed: 8 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -146,6 +146,11 @@ See also this [documentation](https://webdriver.io/docs/assertion/#migrating-fro
146
146
### Jasmine
147
147
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.
148
148
149
+
Jasmine differs from other assertion libraries in two key ways:
150
+
1. Jasmine performs soft assertions by default, collecting failures and only failing the test at the end. Because of this, the SoftAssertion service is not needed or supported.
151
+
2. Forcing `expectAsync` as `expect` (by `@wdio/jasmine-framework`) makes even basic matchers asynchronous. However, since Jasmine handles all promises at the end of the test, assertions appear to work properly—unlike in other frameworks, where using `await` is mandatory for correct behavior.
152
+
- Note: This goes against [this recommendation](https://jasmine.github.io/api/edge/async-matchers) and could cause unexpected issues.
153
+
149
154
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.
150
155
151
156
#### Jasmine `expectAsync`
@@ -173,14 +178,14 @@ Expected in `tsconfig.json`:
173
178
```
174
179
175
180
#### Global `expectAsync` force as `expect`
176
-
When the global ambiant is the `expect`of wdio but forced to be `expectAsync` under the hood, like when using `@wdio/jasmine-framework`, then even the basic matchers need to be awaited
181
+
When the global ambient `expect`is actually `expectAsync` under the hood (as with `@wdio/jasmine-framework`), it is recommended to `await` even basic matchers, even though Jasmine will handle any un-awaited assertions at the end of the test.
177
182
178
183
```ts
179
184
describe('My tests', async () => {
180
185
it('should verify my browser to have the expected url', async () => {
// Even basic matchers requires expect since they are promises underneath
188
+
// Even basic matchers should have `await` since they are promises underneath
184
189
awaitexpect(true).toBe(true)
185
190
})
186
191
})
@@ -249,4 +254,4 @@ It is recommended to build your project using this approach instead of relying o
249
254
250
255
### Cucumber
251
256
252
-
Moredetailstocome. Inshort, whenpairedwith`@wdio/cucumber-framework`, youcanuseWDIO's expect with Cucumber and even [Gherkin](https://www.npmjs.com/package/@cucumber/gherkin).
257
+
Moredetailstocome. Inshort, whenpairedwith`@wdio/cucumber-framework`, youcanuseWDIO's expect with Cucumber and even [Gherkin](https://www.npmjs.com/package/@cucumber/gherkin).
* Overrides the default wdio `expect` for Jasmine case specifically since the `expect` is now completely asynchronous which is not the case under Jest or standalone.
30
+
* Overrides the default WDIO expect specifically for Jasmine, since `expectAsync` is forced into `expect`, making all matchers fully asynchronous. This is not the case under Jest or Mocha.
31
+
* Using `jasmine.AsyncMatchers` pull on WdioMatchers above but also allow to using Jasmine's built-in matchers and also `withContext` matcher.
0 commit comments