LoginSignup
5
0

More than 1 year has passed since last update.

ReactコンポーネントのテストケースをChromeでデバッグする

Last updated at Posted at 2021-05-10

ReactというよりJestの機能ですが、Reactコンポーネントのユニットテストは、Chromeでデバッグできます。

1. テストケースでBreakPointを設定したい場所にdebugger文を書く

通常のデバッグと同じです。

  expect(tree).toMatchSnapshot();

  debugger

  // manually trigger the callback

2. デバッグオプション付きでJestを起動

$ node --inspect-brk node_modules/.bin/jest --findRelatedTests [テストケースへのパス]

デバッガの接続待ちで停止する

Debugger listening on ws://127.0.0.1:9229/4e252f35-9932-4144-ad7e-cd9c659a0b86
For help, see: https://nodejs.org/en/docs/inspector

3. ChromeのURLからchrome://inspectを入力

Screen Shot 2021-05-11 at 6.56.08.jpg

4. Target - inspectをクリックしてデバッガを立ち上げる

右上のResume script Executionで実行すると、BraekPointを設定した位置で停止する。

Image from Gyazo

通常のデバッグと同じく、consoleから変数の内容の確認などができる

参考

5
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
5
0