我正在尝试为我的简单的 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";
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();
});
});
任何关于我如何解决这个问题的建议都是值得赞赏的。