Launch configuration for single test debugging in vscode

If you want to debug your single jest test case using vscode, here you go;  

Before you start;

Check how debugging works in vscode https://code.visualstudio.com/docs/introvideos/debugging

Use the code snippet below;

Add the code below in configurations of the .vscode/launch.json. Make sure to replace them #~ ~# on below code snippet.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
    {
      "type": "node",
      "request": "launch",
      "name": "Jest Tests",
      "program": "${workspaceFolder}/node_modules/jest/bin/jest.js",
      "disableOptimisticBPs": true,
      "console": "integratedTerminal",
      "args": [
        "--i",
        "--config",
        "jest.config.js",
        "--",
        "#~Provide the test file path here~#",
        "--runTestsByPath",
        "--testNamePattern",
        "\"^#~Provide the test name pattern here (Scenario name\\sTest Case name)~#\""
      ],
      "env": {
        "TZ": "Etc/UTC"
      }
    }

Finally, it should look like;

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.