使用自定义匹配器扩展 expect-webdriverio

Extending expect-webdriverio with custom matchers

我需要为我的 wdio 打字稿框架制作一个自定义匹配器。我查看了 https://github.com/webdriverio/expect-webdriverio/blob/master/docs/Extend.md 并完成了所有操作,我复制并粘贴了完全相同的代码。所以在我的 before() 钩子中:

const matchers = require('myMatchers');
matchers.addCustomMatchers();

在我的 wdio conf 文件旁边:

module.exports = {
    addCustomMatchers: () => {
        console.log("MY MATCHER");
        expect.extend({
            myMatcher(actual, expected) {
                return { pass: actual === expected, message: () => 'some message' }
            },
        })
    }
}

当我开始测试时,我在控制台中看到“MY MATCHER”行。所以它得到正确执行。 但是我在尝试做期望时看不到 myMatcher。我错过了什么?

文档有效。对于 TypeScript 项目,您还必须声明类型。

查看我的示例项目:

  1. before hook
  2. matchers
  3. matcher types
  4. usage in test

注意: 请确保您拥有最新的 wdio 软件包和有效的 tsconfig.json。您可以在项目中找到所有这些内容。