1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

VSCodeでVitestで書いたテストコードをBreakpointを使ってデバッグしよう!

Posted at

概要

Vitestでフロントエンドのテストをデバッグする際にブレークポイントを使用する方法について解説します

前提

  • すでにVitestやReactの環境構築が完了済みであること

手順

VSCodeのターミナル上でJavascript デバッグ ターミナルを開きます

スクリーンショット 2023-11-26 8.46.20.png

続いて

npm run test

を実行します

実行すると以下のようにデバッガーが起動します

Debugger attached.

> project@0.0.0 test
> vitest --watch

Debugger attached.

すると、以下のようにブレークポイントによるデバッグができます
スクリーンショット 2023-11-26 8.33.37.png

変数の中身もこのように確認できます
スクリーンショット 2023-11-26 8.54.01.png

デバッグコンソール上でも変数の中身も確認できます
スクリーンショット 2023-11-26 8.54.44.png

デバッグコンソールから変数を直接参照したり変数の中身を変更することもできます
スクリーンショット 2023-11-26 8.55.33.png

まとめ

テストを実行するたびに毎回console.logを記載したりするのはめんどくさいので便利な機能は積極的に使いましょう

参考

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?