我正在尝试为我的简单 React 应用程序编写测试,该应用程序使用 API 等为狗收容所创建 UI。我导入了如下所示的module并运行了以下命令
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";
import "jest-dom/extend-expect";
import * as React from "react";
import PetCard from "./PetCard";
import Pet from "./Pet";
import { render } from "react-testing-library";
const petMock = {
id: "225c5957d7f450baec75a67ede427e9",
name: "Fido",
status: "available",
kind: "dog",
breed: "Labrador",
} as Pet;
describe("PetCard", () => {
it("should render the name", () => {
const { getByText } = render(<PetCard pet={petMock} />);
expect(getByText("Fido")).toBeInTheDocument();
});
});
任何有关我如何解决此问题的建议表示赞赏。