Scraps 最終更新 2026/10/08 19:01

原文著者: @keikeigo /

「TestingLibraryElementError: Found multiple elements with the text」の解決方法【Vitest/React Testing Library】

  • #フロントエンド
  • #テスト
  • #DevOps・CI/CD

AIで作成し、掲載基準に基づいて自動選定した要約です。

  • VitestでReactテスト中に複数のDOMがレンダリングされてエラーが発生
  • beforeEachでrenderを実行しafterEachでcleanupを追加、またはグローバルにafterEachを設定
  • テストごとにDOMをクリーンアップしないとエラーが発生するため、afterEachでcleanupを実行する
「TestingLibraryElementError: Found multiple elements with the text」の解決方法【Vitest/React Testing Library】 - Qiita

Qiita / 原文を読む