Vivek
Vivek

Reputation: 775

How to debug jasmine karma tests with VSCode tool

I am using Visual Studio Code for writing jasmine and karma based unit test cases. I would like to know if there is a way to debug tests in vs code tool itself.

Upvotes: 7

Views: 15314

Answers (1)

MkMan
MkMan

Reputation: 2191

  1. Open the debug tab
  2. Add a Chrome configuration, it'll fill out most the fields for you. For the port change it to 9876 (or whatever is specified in your karma.conf.js). See below.
  3. Set breakpoint(s) in the code you want to debug
  4. Run your the debug task which will open a chrome window to the specified port
  5. Run your test command (ng test) and refresh the opened Chrome window if necessary

Sample configuration, they are created in a filed called launch.json

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "chrome",
            "request": "launch",
            "name": "Launch Chrome against localhost",
            "url": "http://localhost:9876",
            "webRoot": "${workspaceFolder}"
        }
    ]
}

Upvotes: 7

Related Questions