Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
9683aac
Working case with only matchers
dprevost-LMI Jun 22, 2025
7b69c77
Block toHaveUrl on element
dprevost-LMI Jun 22, 2025
7b85731
Working overloaded snapshot in jest
dprevost-LMI Jun 22, 2025
07f43ae
A good working case with standalone + add back snapshot
dprevost-LMI Jun 22, 2025
9a72d90
A good working version of standalone
dprevost-LMI Jun 22, 2025
74fc414
Code review + add a toBe with element + chainable
dprevost-LMI Jun 22, 2025
ffac6f7
Bring back `snapshot.test.ts`
dprevost-LMI Jun 22, 2025
b254057
Bring back toBeRequestedWith
dprevost-LMI Jun 22, 2025
f5d9cbf
Bring back `toBeRequestedWith`
dprevost-LMI Jun 22, 2025
53317aa
Pretty solid typing for both Jest & mocha (standalone)
dprevost-LMI Jun 23, 2025
2d4fb6e
Bring back soft assertion + add tsc + code review
dprevost-LMI Jun 23, 2025
4cac925
Code review
dprevost-LMI Jun 23, 2025
fc92f7e
Code review + add linter in types
dprevost-LMI Jun 23, 2025
47faaee
Add decent not finished typing for Jasmine + soft assertion
dprevost-LMI Jun 23, 2025
a75fecc
ish working with jasmine expect and matcher + fix unimplemented method
dprevost-LMI Jun 24, 2025
ff52916
Use `ExpectWebdriverIO` where we can to be more verbose
dprevost-LMI Jun 24, 2025
85e0fad
Separate Browser, mock and element matcher + better typing
dprevost-LMI Jun 24, 2025
b7fa0a1
fix rebase + add more UT typing cases
dprevost-LMI Jun 24, 2025
7ecd093
Review test template to be better
dprevost-LMI Jun 24, 2025
a1d32a5
Add a working case of custom matchers with types!
dprevost-LMI Jun 24, 2025
59a287c
Remove this file
dprevost-LMI Jun 25, 2025
ece01bd
Fix rebase
dprevost-LMI Jun 25, 2025
144611b
Copy better type testing to mocha + clean package.json
dprevost-LMI Jun 25, 2025
e8b9432
Working asymmetric matcher
dprevost-LMI Jun 26, 2025
267b4da
Apply suggestions from code review
dprevost-LMI Jun 25, 2025
c597d88
Update types/expect-webdriverio.d.ts
dprevost-LMI Jun 27, 2025
ed63525
Remove unneeded changes
dprevost-LMI Jun 27, 2025
912faab
Use built-in PromiseLike
dprevost-LMI Jun 27, 2025
5c68ef4
Have snapshot use await only on promises
dprevost-LMI Jun 27, 2025
5dc6e89
More reusable types
dprevost-LMI Jun 27, 2025
75caff7
Validated that asymmetric matchers previously not included works
dprevost-LMI Jun 27, 2025
2d0d058
ignore not needed anymore!
dprevost-LMI Jun 27, 2025
e68e916
Fix some missing options pararmter + dig matchers and still not sure!
dprevost-LMI Jun 27, 2025
3fbf20c
Moving types into expect-webdriverio.d.ts and remove standalone.d.ts
dprevost-LMI Jun 27, 2025
2b138b0
Move new mocha test to jest, review + simplify jest.d.ts
dprevost-LMI Jun 27, 2025
e28a899
Simplify further jest.d.ts
dprevost-LMI Jun 27, 2025
20aa50a
Finalize simplification of Jest namespace
dprevost-LMI Jun 27, 2025
ea039f9
Test `ExpectWebdriverIO` for custom matcher when using Jest!
dprevost-LMI Jun 27, 2025
b65fe35
Remove unused code!
dprevost-LMI Jun 28, 2025
1d0e64b
Have better tsc check on types but filtering out node_module errors
dprevost-LMI Jun 28, 2025
53db48c
Brin back tsc on types + exclude file in coverage and review %
dprevost-LMI Jun 28, 2025
27968b1
fix and add UT for custom asymmetric matchers
dprevost-LMI Jun 29, 2025
d01529b
Review overloaded functions from `expect` lib
dprevost-LMI Jun 29, 2025
2f8182b
Make inverse matcher works under the ExpectWebDriverIO namespace!
dprevost-LMI Jun 29, 2025
ba08e5a
Make inverse asymmetric matcher works under Jest
dprevost-LMI Jun 29, 2025
82b31de
Upgrade the ts config to more recent values
dprevost-LMI Jun 29, 2025
a33f007
Working types under jasmine
dprevost-LMI Jul 1, 2025
832028f
Add Jasmine case + force the global expect also for Jasmine
dprevost-LMI Jul 1, 2025
1ebc16c
Review jasmine usage in the project
dprevost-LMI Jul 1, 2025
fb74809
Add support for both `@jest/global` and `@types/jest` + add doc
dprevost-LMI Jul 1, 2025
c44baa7
Review defined types in package.json
dprevost-LMI Jul 1, 2025
a3aa5bf
Review doc and fix some type issues
dprevost-LMI Jul 1, 2025
93d0bdd
Doc review
dprevost-LMI Jul 1, 2025
9d2324d
Test and document Jasmine typing
dprevost-LMI Jul 3, 2025
9fd54b5
Fix impact of supporting Jasmine typing
dprevost-LMI Jul 3, 2025
3145c40
Use latest Jest with exportable Inverse
dprevost-LMI Jul 4, 2025
3e4504c
Fix Jasmine left over problem
dprevost-LMI Jul 4, 2025
69057ca
Review some TODOs
dprevost-LMI Jul 4, 2025
a97198d
Simplify Jasmine augmentation
dprevost-LMI Jul 4, 2025
4482755
Add jest types check to the ts command
dprevost-LMI Jul 4, 2025
19a3263
Review doc by the AI
dprevost-LMI Jul 4, 2025
bcaba9b
Review dead link with AI
dprevost-LMI Jul 4, 2025
cfc0af3
Add details with Chai
dprevost-LMI Jul 4, 2025
df5f93d
Remove out of scope TODOs
dprevost-LMI Jul 4, 2025
acaaeb3
Add back promise matchers!
dprevost-LMI Jul 4, 2025
3cebbe1
Review more TODOs
dprevost-LMI Jul 4, 2025
8eacdfa
Add finding on augmentation of `@jest/globals`
dprevost-LMI Jul 5, 2025
60ccb41
Update doc following finding requiring registering matcher with Jest
dprevost-LMI Jul 5, 2025
4f159d2
Align `AssertionResult` and `matchers` type with expect library
dprevost-LMI Jul 6, 2025
e5843b2
Add documentation on required configuration
dprevost-LMI Jul 7, 2025
506d528
Document more findings around soft assertions
dprevost-LMI Jul 7, 2025
8fa83e1
Add known limitations for soft assertions
dprevost-LMI Jul 8, 2025
538bbcb
Clarify usage of `expectAsync`
dprevost-LMI Jul 8, 2025
34408ff
Processing more TODOs
dprevost-LMI Jul 9, 2025
10c1d52
Rebase + clean example + Add note on augmentation limitations
dprevost-LMI Jul 19, 2025
f42f159
Document better limitation of soft assertion with Jasmine
dprevost-LMI Jul 19, 2025
551de19
Add cucumber to doc + fix some errors
dprevost-LMI Jul 19, 2025
d3b00b1
Simplify node constraints
dprevost-LMI Jul 19, 2025
d1be84d
Have `expect(Promise).toBeDefined()` be void and not a Promise
dprevost-LMI Jul 20, 2025
b1795b1
Even jest does not support `expect.not.anything()`
dprevost-LMI Jul 20, 2025
cebf40f
Force expect under Jasmine to always be async
dprevost-LMI Jul 20, 2025
415d3ba
Finalize jasmine support with typing for wdio expect being asyncrhonous
dprevost-LMI Jul 21, 2025
07fe3a3
Revert matchers type breaking changes + better jasmine sync `d.ts` name
dprevost-LMI Jul 21, 2025
58a8244
Have `InverseAsymmetricMatchers` for easier typing
dprevost-LMI Jul 22, 2025
1d11d0a
Update docs/Framework.md
christian-bromann Jul 22, 2025
eefed07
Update docs/Framework.md
christian-bromann Jul 22, 2025
446b182
Update docs/Framework.md
christian-bromann Jul 22, 2025
4f32ad2
Update docs/Framework.md
christian-bromann Jul 22, 2025
66cd08a
Update docs/Framework.md
christian-bromann Jul 22, 2025
e242f3b
Update docs/Framework.md
christian-bromann Jul 22, 2025
888f8ff
Update docs/Framework.md
christian-bromann Jul 22, 2025
64e9198
Update docs/Framework.md
christian-bromann Jul 22, 2025
79516ea
Update docs/Framework.md
christian-bromann Jul 22, 2025
4092e00
Update docs/Framework.md
christian-bromann Jul 22, 2025
e12557c
Update jasmine-wdio-expect-async.d.ts
christian-bromann Jul 22, 2025
f716df6
Update docs/Framework.md
christian-bromann Jul 22, 2025
dc6486e
Update docs/Framework.md
christian-bromann Jul 22, 2025
cc9aafc
Update docs/Framework.md
christian-bromann Jul 22, 2025
743d98f
Update docs/Framework.md
christian-bromann Jul 22, 2025
2576b38
Merge branch 'main' into enhanced-expect-wdio-typing
dprevost-LMI Aug 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
!lib/**/*.js
!types/**/*.d.ts
!jasmine.d.ts
!jasmine-wdio-expect-async.d.ts
!jest.d.ts
!LICENSE
!package.json
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# expect-webdriverio [![Test](https://github.com/webdriverio/expect-webdriverio/actions/workflows/test.yml/badge.svg)](https://github.com/webdriverio/expect-webdriverio/actions/workflows/test.yml)


###### [API](docs/API.md) | [TypeScript / JS Autocomplete](/docs/Types.md) | [Examples](docs/Examples.md) | [Extending Matchers](/docs/Extend.md)
###### [API](docs/API.md) | [TypeScript / JS Autocomplete](docs/Types.md) | [Examples](docs/Examples.md) | [Extending Matchers](docs/CustomMatchers.md)

> [WebdriverIO](https://webdriver.io/) Assertion library inspired by [expect](https://www.npmjs.com/package/expect)

Expand Down
9 changes: 7 additions & 2 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ When set to `true` (default), the service will automatically assert all soft ass

This is useful if you want full control over when soft assertions are verified or if you want to handle soft assertion failures in a custom way.

### Known limitations

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

## Default Options

These default options below are connected to the [`waitforTimeout`](https://webdriver.io/docs/options#waitfortimeout) and [`waitforInterval`](https://webdriver.io/docs/options#waitforinterval) options set in the config.
Expand Down Expand Up @@ -667,7 +672,7 @@ await expect(mock).toBeRequestedTimes({ gte: 5, lte: 10 }) // request called at

Checks that mock was called according to the expected options.

Most of the options supports expect/jasmine partial matchers like [expect.objectContaining](https://jestjs.io/docs/en/expect#expectobjectcontainingobject)
Most of the options supports expect/jasmine partial matchers like [expect.objectContaining](https://jestjs.io/docs/expect#expectobjectcontainingobject)

##### Usage

Expand Down Expand Up @@ -858,7 +863,7 @@ await expect(elem).toHaveElementClass(/Container/i)

## Default Matchers

In addition to the `expect-webdriverio` matchers you can use builtin Jest's [expect](https://jestjs.io/docs/en/expect) assertions or [expect/expectAsync](https://jasmine.github.io/api/3.5/global.html#expect) for Jasmine.
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.

## Asymmetric Matchers

Expand Down
4 changes: 2 additions & 2 deletions docs/Extend.md → docs/CustomMatchers.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

Similar to how `expect-webdriverio` extends Jasmine/Jest matchers it's possible to add custom matchers.

- Jasmine see [custom matchers](https://jasmine.github.io/2.5/custom_matcher.html) doc
- Everyone else see Jest's [expect.extend](https://jestjs.io/docs/en/expect#expectextendmatchers)
- [Jasmine](https://jasmine.github.io/) see [custom matchers](https://jasmine.github.io/tutorials/custom_matchers) doc
- Everyone else see [Jest's expect.extend](https://jestjs.io/docs/expect#expectextendmatchers)

Custom matchers should be added in wdio `before` hook

Expand Down
2 changes: 1 addition & 1 deletion docs/Examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('suite', () => {
WebdriverIO test runner
- Mocha https://github.com/mgrybyk/webdriverio-devtools
- Cucumber https://gitlab.com/bar_foo/wdio-cucumber-typescript
- Jasmine https://github.com/mgrybyk/wdio-jasmine-boilerplate
- Jasmine https://github.com/webdriverio/jasmine-boilerplate

Standalone
- Jest https://github.com/erwinheitzman/jest-webdriverio-standalone-boilerplate
Expand Down
252 changes: 252 additions & 0 deletions docs/Framework.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
# Expect-WebDriverIO Framework

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. Yes, this is a package of Jest but it is usable without Jest.

## Compatibility

We can pair `expect-webdriverio` with [Jest](https://jestjs.io/), [Mocha](https://mochajs.org/), and [Jasmine](https://jasmine.github.io/) and even [Cucumber](https://www.npmjs.com/package/@cucumber/cucumber)

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.

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.

### Jest
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).
- Note: Jest maintainers do not support [`@types/jest`](https://www.npmjs.com/package/@types/jest). If this library gets out of date or has problems, support might be dropped.
- Note: With Jest, the matchers `toMatchSnapshot` and `toMatchInlineSnapshot` are overloaded. To resolve the types correctly, `expect-webdriverio/jest` must be last.

#### With `@jest/globals`
When paired only with [`@jest/globals`](https://www.npmjs.com/package/@jest/globals), we should `import` the `expect` function from `expect-webdriverio`.

```ts
import { expect } from 'expect-webdriverio'
import { describe, it, expect as jestExpect } from '@jest/globals'

describe('My tests', async () => {
it('should verify my browser to have the expected url', async () => {
await expect(browser).toHaveUrl('https://example.com')
})
})
```

No `types` are expected in `tsconfig.json`.
Optionally, to avoid needing `import { expect } from 'expect-webdriverio'`, you can use the following:


```json
{
"compilerOptions": {
"types": ["expect-webdriverio/expect-global"]
}
}
```
##### Augmenting `@jest/globals` JestMatchers
Multiple attempts were made to augment `@jest/globals` to support `expect-webdriverio` matchers directly on JestMatchers. 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.

This [Jest issue](https://github.com/jestjs/jest/issues/12424) seems to target this problem, but it is still in progress.

#### With `@types/jest`
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.

If you are NOT using WDIO Testrunner, some prerequisite configuration is required.

Option 1: Replace the expect globally with the `expect-webdriverio` one:
```ts
import { expect } from "expect-webdriverio";
(globalThis as any).expect = expect;
```

Option 2: Reconfigure Jest's expect with the custom matchers and the soft assertion:
```ts
// Configure the custom matchers:
import { expect } from "@jest/globals";
import { matchers } from "expect-webdriverio";

beforeAll(async () => {
expect.extend(matchers as Record<string, any>);
});
```

[Optional] For the soft assertion, the `createSoftExpect` is currently not correctly exposed but the below works:
```ts
// @ts-ignore
import * as createSoftExpect from "expect-webdriverio/lib/softExpect";

beforeAll(async () => {
Object.defineProperty(expect, "soft", {
value: <T = unknown>(actual: T) => createSoftExpect.default(actual),
});

// Add soft assertions utility methods
Object.defineProperty(expect, "getSoftFailures", {
value: (testId?: string) => SoftAssertService.getInstance().getFailures(testId),
});

Object.defineProperty(expect, "assertSoftFailures", {
value: (testId?: string) => SoftAssertService.getInstance().assertNoFailures(testId),
});

Object.defineProperty(expect, "clearSoftFailures", {
value: (testId?: string) => SoftAssertService.getInstance().clearFailures(testId),
});
});
```

Then as shown below, no imports are required and we can use WDIO matchers directly on Jest's `expect`:
```ts
describe('My tests', async () => {
it('should verify my browser to have the expected url', async () => {
await expect(browser).toHaveUrl('https://example.com')
})
})
```

Expected in `tsconfig.json`:
```json
{
"compilerOptions": {
"types": [
"@types/jest",
"expect-webdriverio/jest" // Must be last for overloaded matchers `toMatchSnapshot` and `toMatchInlineSnapshot`
]
}
}
```

### Mocha
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).

#### Standalone
No import is required; everything is set globally.

```ts
describe('My tests', async () => {
it('should verify my browser to have the expected url', async () => {
await expect(browser).toHaveUrl('https://example.com')
})
})
```

Expected in `tsconfig.json`:
```json
{
"compilerOptions": {
"types": [
"@types/mocha",
"expect-webdriverio/expect-global"
]
}
}
```

#### Chai
`expect-webdriverio` can coexist with the [Chai](https://www.chaijs.com/) assertion library by importing both libraries explicitly.
See also this [documentation](https://webdriver.io/docs/assertion/#migrating-from-chai).

### Jasmine
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.

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.

#### Jasmine `expectAsync`
When not using `@wdio/globals/types` or having `@types/jasmine` before it, the Jasmine expect is shown as the global ambient type. Therefore, when also defining `expect-webdriverio/jasmine`, we can use WDIO custom matchers on the `expectAsync`. Without `@wdio/jasmine-framework`, matchers will need to be registered manually.

```ts
describe('My tests', async () => {
it('should verify my browser to have the expected url', async () => {
await expectAsync(browser).toHaveUrl('https://example.com')
await expectAsync(true).toBe(true)
})
})
```

Expected in `tsconfig.json`:
```json
{
"compilerOptions": {
"types": [
"@types/jasmine",
"expect-webdriverio/jasmine"
]
}
}
```

#### Global `expectAsync` force as `expect`
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

```ts
describe('My tests', async () => {
it('should verify my browser to have the expected url', async () => {
await expect(browser).toHaveUrl('https://example.com')

// Even basic matchers requires expect since they are promises underneath
await expect(true).toBe(true)
})
})
```

Expected in `tsconfig.json`:
```json
{
"compilerOptions": {
"types": [
"@wdio/globals/types",
"@wdio/jasmine-framework",
"@types/jasmine",
"expect-webdriverio/jasmine-wdio-expect-async", // Force expect to return Promises
]
}
}
```

#### `expect` of `expect-webdriverio`
It is preferable to use the `expect` from `expect-webdriverio` to guarantee future compatibility.

```ts
// Required if we do not force the 'expect-webdriverio' expect globally with `"expect-webdriverio/expect-global"`
import { expect as wdioExpect } from 'expect-webdriverio'

describe('My tests', async () => {
it('should verify my browser to have the expected url', async () => {
await wdioExpect(browser).toHaveUrl('https://example.com')

// No required await
wdioExpect(true).toBe(true)
})
})


Expected in `tsconfig.json`:
```json
{
"compilerOptions": {
"types": [
"@types/jasmine",
// "expect-webdriverio/expect-global", // Optional to have the global ambient expect the one of wdio
]
}
}
```


#### Asymmetric matchers
Asymmetric matchers have limited support. Even though `jasmine.stringContaining` does not produce a typing error, it may not work even with `@wdio/jasmine-framework`. However, the example below should work:

```ts
describe('My tests', async () => {
it('should verify my browser to have the expected url', async () => {
await expectAsync(browser).toHaveUrl(wdioExpect.stringContaining('WebdriverIO'))
})
})
```


### Jest & Jasmine Augmentation Notes

If you are already using Jest or Jasmine globally, using `import { expect } from 'expect-webdriverio'` is the most compatible approach, even though augmentation exists.
It is recommended to build your project using this approach instead of relying on augmentation, to ensure future compatibility and avoid augmentation limitations. See [this issue](https://github.com/webdriverio/expect-webdriverio/issues/1893) for more information.

### Cucumber

More details to come. In short, when paired with `@wdio/cucumber-framework`, you can use WDIO's expect with Cucumber and even [Gherkin](https://www.npmjs.com/package/@cucumber/gherkin).
23 changes: 19 additions & 4 deletions docs/Types.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
# Types Definition
## TypeScript

If you are using the [WDIO Testrunner](https://webdriver.io/docs/clioptions) everything will be automatically setup. Just follow the [setup guide](https://webdriver.io/docs/typescript#framework-setup) from the docs. However if you run WebdriverIO with a different testrunner or in a simple Node.js script you will need to add `expect-webdriverio` to `types` in the `tsconfig.json`.

- `"expect-webdriverio"` for everyone except of Jasmine/Jest users.
- `"expect-webdriverio/jasmine"` Jasmine
- `"expect-webdriverio/jest"` Jest
- `"expect-webdriverio"` for everyone except Jasmine/Jest users.
- `"expect-webdriverio/jasmine"` for [Jasmine](https://jasmine.github.io/)
- `"expect-webdriverio/jest"` for [Jest](https://jestjs.io/)
- `"expect-webdriverio/expect-global"` // Optional, if you wish to use expect of `expect-webdriverio` globally without explicit import
- Note: Same as the former `"expect-webdriverio/types"`, now deprecated!

## JavaScript (VSCode)

It's required to create `jsconfig.json` in project root and refer to the type definitions to make autocompletion work in vanilla js.
It's required to create [`jsconfig.json`](https://code.visualstudio.com/docs/languages/jsconfig) in project root and refer to the type definitions to make autocompletion work in vanilla js.

```json
{
Expand All @@ -19,3 +22,15 @@ It's required to create `jsconfig.json` in project root and refer to the type de
]
}
```

## Jasmine special case
[Jasmine](https://jasmine.github.io/) is different from [Jest](https://jestjs.io/) or the standard `expect` definition since it supports promises using `expectAsync` which makes it quite challenging.

Even though this library by itself is not fully Jasmine-ready, it offers the types of the matcher only on the `AsyncMatcher` since using `jasmine.expect` does not work out-of-the-box. However, if you are pulling on the `expect` of `expect-webdriverio`, you will be able to have the WebDriverIO matcher types on `expect`.

Support of `expectAsync` keyword is subject to change and may be dropped in the future!

### Dependency on `@wdio/jasmine-framework`
As mentioned above, this library alone is not working with Jasmine. It is required to manually do some tweaks, or it is strongly recommended to also pair it with `@wdio/jasmine-framework`. See [Framework.md](Framework.md) for more information.

When using [`@wdio/jasmine-framework`](https://www.npmjs.com/package/@wdio/jasmine-framework), since it replaces `jasmine.expect` with `jasmine.expectAsync`, then matchers are usable on the keyword `expect`, but still typing on `expect` directly from [Jasmine](https://jasmine.github.io/) namespace is not supported as of today!
22 changes: 22 additions & 0 deletions jasmine-wdio-expect-async.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/// <reference types="./types/expect-webdriverio.d.ts"/>

/**
* 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.
*/
declare namespace ExpectWebdriverIO {
interface Expect extends ExpectWebdriverIO.AsymmetricMatchers, ExpectLibInverse<ExpectWebdriverIO.InverseAsymmetricMatchers>, WdioExpect {
/**
* The `expect` function is used every time you want to test a value.
* You will rarely call `expect` by itself.
*
* expect function declaration contains two generics:
* - T: the type of the actual value, e.g. any type, not just WebdriverIO.Browser or WebdriverIO.Element
* - R: the type of the return value, e.g. Promise<void> or void
*
* Note: The function must stay here in the namespace to overwrite correctly the expect function from the expect library.
*
* @param actual The value to apply matchers against.
*/
<T = unknown>(actual: T): ExpectWebdriverIO.MatchersAndInverse<Promise<void>, T>
}
}
Loading