LoginSignup
0
0

More than 1 year has passed since last update.

reactテストでハマった話 getting TypeError: expect(...).toBeInTheDocument is not a function

Posted at

タイトル通りです。
2021/07/25において確認された事象。
ライブラリのかみ合わせが良くなかった様子です。

npx create-react-app --template typescript

にてreact × typescriptのプロジェクトを作成した後。
各コマンドの確認を行おうと思い、

npm run test

を実行したら以下のようなエラーを吐きました。

getting TypeError: expect(linkElement).toBeInTheDocument is not a function

エラーをまんま検索すると、
ドンピシャで解決策ありました。
https://github.com/testing-library/jest-dom/issues/167

ちなみに初期のバージョンは以下

    "@testing-library/jest-dom": "^5.14.1",
    "@testing-library/react": "^11.2.7",

これから、

    "@testing-library/jest-dom": "^5.5.0",
    "@testing-library/react": "^10.0.3",

こちらに変更することで解決できました。
バージョンのかみ合わせが悪い場合のエラーはハマると中々抜け出せないので大変ですね。
インストール時にエラー吐かれるとホントに困るので早く修正してほしいです:frowning2:

0
0
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
0
0