Debug a Jest test
Need to debug a test in Jest but can't figure out how? Or possibly you have a react-native app and you can't figure out how to debug a component?
Run jest via the node
command so that the flag of --inspect-brk
can be added.
node --inspect-brk ./node_modules/jest/bin/jest.js --runInBand
From the docs:
The
--runInBand
cli option makes sure Jest runs the test in the same process rather than spawning processes for individual tests. Normally Jest parallelizes test runs across processes but it is hard to debug many processes at the same time.
Then open your chromium based browser (chrome, brave, etc...) and go to about:inspect
. This will open the dev tools where you can select 'Open dedicated DevTools for Node'.
Then you'll see the node dev tools window open.
Now just enter a debugger whereever you need and run the jest command from above.
Tweet