screen.getByText(match: Matcher)接受类型为string | RegExp | MatcherFunction的Matcher,在后者的情况下,类型为(content: string, element: HTMLElement) => boolean。
期望:screen.getByText((content, element) => element.className.includes("my-class") && content.includes("text to search for"));在DOM中搜索带有文本text to search for的类my-class的元素
Actual: TestingLibraryElementError:找不到包含以下文本的元素:element.className.includes(“my-TestingLibraryElementError”) && content.includes(“要搜索的文本”)
就像MatcherFunction原型被解析成字符串一样?会不会是因为lambda语法?
发布于 2021-05-18 09:09:17
这是您所期望的工作方式。函数正在执行并返回,而您的测试正在失败。测试运行器实际上没有办法用简单的英语告诉你你的函数做了什么,所以它简化了你在关于失败的输出消息中搜索的东西(可以是字符串、正则表达式或函数)。
你可能会说这是一个糟糕的开发经验,你是对的。但看起来一切都在按预期进行。
https://stackoverflow.com/questions/67578332
复制相似问题