Jestのコマンドは
「どのテストを、どう実行するか?」 を決めるオプションが豊富。
-watch
-updateSnapshot
/ u
-coverage
目的によって使い分ければ、
テストの時間短縮 & 効率アップ!
コマンド | 意味 | よく使うシーン |
---|---|---|
npx jest |
全テストを実行 | 通常のテスト |
npx jest MyComponent.spec.ts |
指定ファイルだけテスト | 個別ファイルを確認したいとき |
npx jest -t 'テスト名の一部' |
特定の describe / it 名だけ実行 | 1ケースだけ動かしたいとき |
オプション | 説明 | 使い方 |
---|---|---|
--watch |
ファイルの変更を監視 → 自動で再実行 | npx jest --watch |
--watchAll |
すべてのファイルを監視 | npx jest --watchAll |
--coverage |
カバレッジ(網羅率)を出す | npx jest --coverage |
--verbose |
各テストケースの詳細を表示 | npx jest --verbose |
--detectOpenHandles |
非同期で終わってない処理を教えてくれる | npx jest --detectOpenHandles |
オプション | 説明 | 使い方 |
---|---|---|
--updateSnapshot |
スナップショットを更新 | npx jest --updateSnapshot |
-u |
↑ の短縮版 | npx jest -u |