I can\'t find any information on debugging my unit tests written with Jest.
How do you debug Jest Tests ?
You can use Chrome DevTools to debug Jest tests.
First, start Node debugger in your project:
node --inspect-brk --runInBand
Examples:
If you install Jest locally (Linux example):
node --inspect-brk ./node_modules/jest/bin/jest.js --runInBand mymodule/test.js
If you install Jest globally (Windows example):
node --inspect-brk "C:\\Program Files\\nodejs\\node_modules\\jest\\bin\\jest.js" --runInBand mymodule\\test.js
Then, you can open the Google Chrome browser, and type in the address bar:
chrome://inspect
Now click the inspect link under "Remote Target" to open Chrome DevTools.
Note that you probably need to add the source code folder to the workspace in chrome-devtools, so as to be able to set breakpoints.
Now you can press F8 to start debugging.
[FYI]:
[Update] Regarding the step of adding the source code folder to the workspace in chrome-devtools (as asked by Sam), it looks like below:
And then you can open your script files and set the breakpoints:
You find the simple demo project on my GitHub repo.