Debugging Unit Tests — Setup and Inspect
You can debug JavaScript unit tests running in Node.js (like Jest or Mocha) by launching the test runner with inspection enabled. Use the following command to start tests and pause on the first line:
node --inspect-brk ./node_modules/.bin/jest --runInBand
The --inspect-brk
flag starts the V8 inspector and stops at the first line. Adding --runInBand
ensures tests run in a single process, which is essential for reliable debugging.