小编Fra*_*nda的帖子

使用 react-testing-library 测试样式化组件

我目前正在尝试使用 Mocked Provider 测试样式组件,如下所示:

import React from "react";
import TestResults from "./TestResults";
import {
  render,
  cleanup,
  findByTestId,
  findByText,
  waitForElement,
} from "@testing-library/react";
import { MockedProvider } from "@apollo/react-testing";




describe("TestResultsComponent", () => {
  describe("Overall", () => {
    it("should render successfully - base", async () => {
      const { getByText } = render(
        <MockedProvider>
          <TestResults />
        </MockedProvider>
      );
      expect(getByText("Preview")).toBeInTheDocument();
    });
  });
});
Run Code Online (Sandbox Code Playgroud)

我在 TestResults 文件中使用 makeStyles 钩子

当我运行我的测试时,我收到以下错误:

TypeError: theme.spacing is not a function
 Material-UI: the `styles` argument provided is invalid.
      You …
Run Code Online (Sandbox Code Playgroud)

unit-testing reactjs react-apollo apollo-client react-testing-library

3
推荐指数
1
解决办法
4082
查看次数