Skip to content

Instantly share code, notes, and snippets.

@willianfalbo
Last active January 5, 2023 20:40
Show Gist options
  • Save willianfalbo/d051fd4e620a0a731c8efcdfa6957238 to your computer and use it in GitHub Desktop.
Save willianfalbo/d051fd4e620a0a731c8efcdfa6957238 to your computer and use it in GitHub Desktop.

How to debug Unit Tests (Jest)

In your VSCode, make sure your .vscode/launch.json file has the following configuration:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "attach",
      "name": "Attach",
      "port": 9229
    }
  ]
}

Place a debugger; statement in any of your tests. Then, in your project's directory, run:

node --inspect-brk node_modules/.bin/jest --runInBand
# or on Windows
node --inspect-brk ./node_modules/jest/bin/jest.js --runInBand

Finally, go to "Run and Debug" in the Explorer, select "Attach" and click on "Start Debugging".

Also, you can watch the video tutorial here: https://www.loom.com/share/3c72296c132449a18906a4b6a7d23cc1

References: https://jestjs.io/docs/troubleshooting#debugging-in-vs-code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment