Skip to content

Latest commit

 

History

History
43 lines (34 loc) · 1.52 KB

File metadata and controls

43 lines (34 loc) · 1.52 KB

Custom Matchers

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-framework provides an out-of-the-box experience.
    • Else, register matchers manually with jasmine.addAsyncMatchers, then they will be available on expectAsync.
  • Types: Type augmentation for custom matchers is provided. See Types.md for details.

Adding your own matchers

Similar to how expect-webdriverio provide custom matchers it's possible to add your own custom matchers.

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' }
        }
    })
}