Why not login to Qiita and try out its useful features?

We'll deliver articles that match you.

You can read useful information later.

3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Cannot find module '@testing-library/jest-dom/extend-expect'エラーが出る

Posted at

はじめに

Jestを設定していたときにChatGPTに頼っていたところうまく行かなかったのでまとめます

問題

以下のテストを書いたところエラーが出ました

page.test.tsx
import React from "react";
import { render, screen } from "@testing-library/react";
import "@testing-library/dom";
import { About } from "../page";

describe("About", () => {
  it("Aboutというタイトルがあること", () => {
    render(About());
    const aboutImage = screen.getByTestId("about-image").querySelector("img");
    expect(aboutImage!).toBeInTheDocument();
  });
});
 Cannot find module '@testing-library/jest-dom/extend-expect' 

解決方法

そもそも最新の@testing-library/jest-domでは、extend-expectのインポートは不要になりました

なので以下をインポートするだけでうまく動くようになりました

page.test.tsx
import '@testing-library/jest-dom';

おわりに

ChatGPTに頼りすぎると思わぬところで沼ってしまうことがよくわかりました
ある程度のところでネットで調べたり、聞き方を変えてみたりしないといけないです

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up

Qiita Advent Calendar is held!

Qiita Advent Calendar is an article posting event where you post articles by filling a calendar 🎅

Some calendars come with gifts and some gifts are drawn from all calendars 👀

Please tie the article to your calendar and let's enjoy Christmas together!

3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?