Skip to content

Latest commit

 

History

History
33 lines (27 loc) · 957 Bytes

Extend.md

File metadata and controls

33 lines (27 loc) · 957 Bytes

Adding your own matchers

Similar to how expect-webdriverio extends Jasmine/Jest matchers it's possible to add 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' }
        }
    })
}