expect-webdriverio registers WebdriverIO custom matchers out of the box for a seamless experience.
To use WebdriverIO custom matchers (except asymmetric matchers) directly in:
- Jest: Register matchers manually with
expect.extend. - Jasmine: Using
@wdio/jasmine-frameworkprovides an out-of-the-box experience.- Else, register matchers manually with
jasmine.addAsyncMatchers, then they will be available onexpectAsync.
- Else, register matchers manually with
- Types: Type augmentation for custom matchers is provided. See Types.md for details.
Similar to how expect-webdriverio provide custom matchers it's possible to add your own custom matchers.
- Jasmine see custom matchers doc
- Everyone else see Jest's expect.extend
Custom matchers should be added in wdio before hook
// wdio.conf.js
{
async before () {
const { addCustomMatchers } = await import('./myMatchers')
addCustomMatchers()
}
}// myMatchers.js - Jest example
export function addCustomMatchers () {
if (global.expect.expect !== undefined) { // Temporary workaround. See https://github.com/webdriverio/expect-webdriverio/issues/835
global.expect = global.expect.expect;
}
expect.extend({
myMatcher (actual, expected) {
return { pass: actual === expected, message: () => 'some message' }
}
})
}