Jest(version28)でテストを実行したら、TypeError: Cannot read properties of undefined (reading ‘testEnvironmentOptions’)のエラー
$ npm run test
> expo3@1.0.0 test
> jest
FAIL test/App.test.tsx
● Test suite failed to run
TypeError: Cannot read properties of undefined (reading 'testEnvironmentOptions')
at new JSDOMEnvironment (node_modules/jest-environment-jsdom/build/index.js:73:28)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Contents
結論
Jestのバージョンを27に下げたら解決しました。
なぜ、testEnvironmentOptionsがundefinedと表示されたのか、謎のままです。
Jestのバージョンを下げるコマンドは以下の通り実行しました。
npm install -D jest@27 ts-jest@27 @types/jest@27 jest-environment-jsdom@27
Jestのversionとjest-environment-jsdomを一緒にするようにstackoverflowに書かれていたので、最初はversion28に統一してあれこれやりましたが、どうしてもうまくいきませんでした。