React.js/testing-library/react =>;类型错误:无法读取 null 的属性(读取“addEventListener”)
我正在尝试对一些反应组件进行单元测试,并且在一些组件测试中出现了此错误。我尝试了很多解决方案,但没有任何结果
TypeError: Cannot read properties of null (reading 'addEventListener')
- 测试代码
import { fireEvent, render, screen } from "@testing-library/react";
import { act } from "react-test-renderer";
import "@testing-library/jest-dom";
import { Provider } from "react-redux";
import configureStore from "redux-mock-store";
import { initialState } from "./mock";
import "jest-location-mock";
import TabsPanel from "../TabsPanel";
import { usei18n } from "../i18n";
const i18n = usei18n("en");
describe("TabsPanel component", () => {
const mockStore = configureStore();
let store = mockStore(initialState);
test("renders TabsPanel without crashing", async () => {
const { getByTestId } = render(
<Provider store={store}>
<TabsPanel />
</Provider>
);
expect(getByTestId("TabsPanel-component")).toBeTruthy();
});
});
I'm trying to unit test some of react components, and I got this error with some of the component tests. I have tried many solutions but without any result
TypeError: Cannot read properties of null (reading 'addEventListener')
- Test code
import { fireEvent, render, screen } from "@testing-library/react";
import { act } from "react-test-renderer";
import "@testing-library/jest-dom";
import { Provider } from "react-redux";
import configureStore from "redux-mock-store";
import { initialState } from "./mock";
import "jest-location-mock";
import TabsPanel from "../TabsPanel";
import { usei18n } from "../i18n";
const i18n = usei18n("en");
describe("TabsPanel component", () => {
const mockStore = configureStore();
let store = mockStore(initialState);
test("renders TabsPanel without crashing", async () => {
const { getByTestId } = render(
<Provider store={store}>
<TabsPanel />
</Provider>
);
expect(getByTestId("TabsPanel-component")).toBeTruthy();
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论