我正在尝试为我的简单React编写测试,该应用程序使用API等为养狗所创建一个UI。
npm install jest-dom react-testing-library --save-dev
但是,我得到了以红色下划线的toBeInTheDocument();方法和错误消息
"Property 'toBeInTheDocument' does not exist on type 'Matchers<any>'."
import "react-testing-library/cleanup-after-each";
i
Warning: validateDOMNesting(...): <tbody> cannot appear as a child of <div>.
in tbody (created by TableBody)
in TableBody (created by TableBody)
in TableBody
问题:
如何将TableBody组件呈现为table元素,而不是react-testing-library使用的默认div?
补充信息:
我尝试将选项传递到react-testing-library、render()、函数中,但似乎无法
似乎如果你不将Material-UI样式表注入到jest/react-testing-library测试中,那么jsdom将无法从你的组件中获得正确的样式(例如,运行getComputedStyle(component)将为组件返回不正确的样式)。
如何正确设置jest/react- test -library测试,以便将样式正确地注入到测试中?我已经将组件包装在一个主题提供程序中,可以很好地工作。
我正在使用react-testing-library测试一个简单的组件,它内部嵌套了一个react-router-dom的<Link>,我得到了这个错误: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in,
在尝试使用react-testing-library测试React.Suspense时,我遇到了一个奇怪的错误。错误只是说“不支持”,但并没有给出任何真正的洞察问题。我遵循了Kent Dodds did on youtube的例子。 我发布了full code of my problem on github here,但下面是测试代码的快照: import React from "react";
import { render, waitForElement, cleanup } from "react-testing-library";
import My