Open cossack910 opened 1 year ago
公式 https://jestjs.io/ja/docs/getting-started
参考 https://zenn.dev/longbridge/articles/9e9758181c8846
コマンド
docker exec -it reactjest npm install jest --save-dev
docker exec -it reactjest npm install --save-dev jest ts-jest @types/jest
docker exec -it reactjest npm install ts-jest --save-dev
jest.config.jsonを作成
{ "roots": [ "<rootDir>/src" ], "testMatch": [ "**/__tests__/**/*.+(ts|tsx|js)", "**/?(*.)+(spec|test).+(ts|tsx|js)" ], "transform": { "^.+\\.(ts|tsx)$": "ts-jest" }, "testEnvironment": "jsdom" //jest28以降は自動で記載されていない "verbose": true //成功したテストと失敗したテストの表示 }
package.json
"scripts": { ・・・中略・・・ "test": "jest --config ./jest.config.json", //testコマンド実行 jest.config.jsonの階層を記載 "test:watch": "npm run test -- --watch" //ファイル変更時にテスト },
参考 https://stackoverflow.com/questions/72013449/upgrading-jest-to-v29-error-test-environment-jest-environment-jsdom-cannot-be
以下をインストールして対応可能
docker exec -it reactjest npm install -D jest-environment-jsdom
install(vite環境)
公式 https://jestjs.io/ja/docs/getting-started
参考 https://zenn.dev/longbridge/articles/9e9758181c8846
コマンド
jest.config.jsonを作成
package.json