LoginSignup
0
0

More than 1 year has passed since last update.

JestでReactのテスト中にエラー Jest Could not locate module FileName.css (mapped as identity-obj-proxy)

Last updated at Posted at 2022-01-15

背景

Reactアプリのレンダリングについてのテストとして、Jestのスナップショット機能を使用している。

テスト実行時に「Jest Could not locate module FileName.css :mapped as identity-obj-proxy」というエラーメッセージが出力されたのでその解決策をまとめた。

※「FileName.css」にはプロジェクトに存在するCSSファイル名が入る。

> myProject@0.0.1 test C:\Users\admin\Documents\myApp
> jest

FAIL _tests_\Home.test.js
    Test suite failed to run

    Configuration error:

    Could not locate module react-datepicker/dist/react-datepicker-cssmodules.css (mapped as identity-obj-proxy)

    Please check your ○○ for these entries:
    {
      "moduleNameMapper": {
        "/^.+\.(css|less)$/": "identity-obj-proxy"
      },
      "resolver": undefined
    }

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        1.894s
Ran all test suites.
npm ERR! Test failed.  See above for more details.

開発言語 (バージョン情報)

  • React.js (17.0.2)
  • Next.js (11.1.2)
  • TypeScript (4.4.3)
  • Jest (27.2.2)

解決策

ターミナルで以下のコマンドを実行する。ただし実行はpackage.jsonのあるディレクトリでおこなう。

npm install --save-dev identity-obj-proxy

参考

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