You can debug Karma by attaching the debugger to a Chrome instance. You'd want to set your launch.json config to something like this:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "chrome",
            "request": "attach",
            "name": "Attach Karma Chrome",
            "address": "localhost",
            "port": 9333,
            "pathMapping": {
                "/": "${workspaceRoot}/",
                "/base/": "${workspaceRoot}/"
            }
        }
    ]
}

But you also need to adjust your karma.conf.js config, so that it launches Chrome instance with dev tools listening to 9333 port, like so:

browsers: [
  'ChromeDebugging'
],

customLaunchers: {
  ChromeDebugging: {
    base: 'Chrome',
    flags: [ '--remote-debugging-port=9333' ]
  }
},

With such setup you can just run your karma server (with captured browser), and then start debugging in visual studio.

If you'd like to find more details I made a tutorial on debugging Karma with Visual Studio Code.

Answer from Marek Lewandowski on Stack Overflow
🌐
Visual Studio Code
code.visualstudio.com › docs › nodejs › angular-tutorial
Using Angular in Visual Studio Code
November 3, 2021 - The source code where the breakpoint is set runs on startup before the debugger was attached so we won't hit the breakpoint until we refresh the web page. Refresh the page and you should hit your breakpoint. You can step through your source code (F10), inspect variables such as AppComponent, and see the call stack of the client side Angular application.
🌐
Studiolacosanostra
studiolacosanostra.github.io › 2019 › 05 › 16 › How-to-debug-Angular-tests-in-VSCode
How to debug Angular tests in VSCode
April 14, 2024 - Now all you have to do is run ng test in the background. And when you need to check what is happening in a given test, all you have to do is insert a breakpoint on a given line or add debugger, press F5 and you have everything you need.
Discussions

How to debug Karma tests in Visual Studio Code? - Stack Overflow
I want to debug Karma tests in VS Code but I did not find out how. Is there any way to do that or will I have to use another IDE (WebStorm)? More on stackoverflow.com
🌐 stackoverflow.com
How to debug a Angular 4 unit tests using Visual Studio Code
I have a Angular 4 / Material project and are using Visual Studio Code. The project is set up using angular/cli I have started to write some unit tests using Karma and Jasmin. The setup is all don... More on stackoverflow.com
🌐 stackoverflow.com
angular - Debug Tests in NG Test - Stack Overflow
I am using Angular CLI and VSCode but none of my breakpoints in my spec files seem to be getting hit when I run ng test? Do I need to do some config? More on stackoverflow.com
🌐 stackoverflow.com
VSCode: Debug breakpoints not working for ng test
🐞 Bug report Command (mark with an x) new build serve test e2e generate add update lint xi18n run config help version doc Is this a regression? Not sure Description Breakpoints are not hit when deb... More on github.com
🌐 github.com
3
April 16, 2020
🌐
DEV Community
dev.to › angular › setup-jest-for-angular-with-debugging-in-visual-studio-code-2d96
Setup Jest for Angular with Debugging in Visual Studio Code - DEV Community
July 18, 2023 - This article aims to describe a really fast step-by-step way to setup Jest testing for Angular projects including debugging capabilities of Visual Studio Code.
🌐
Brainly
brainly.com › computers and technology › high school › how can you debug an angular unit test in visual studio code?
[FREE] How can you debug an Angular unit test in Visual Studio Code? - brainly.com
November 18, 2023 - To debug Angular unit tests in Visual Studio Code, set breakpoints in your code, run the tests in debug mode from the Activity Bar, and use the debugging tools to inspect variables and navigate through the code.
🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
Angular/Karma Test Explorer - Visual Studio Marketplace
Extension for Visual Studio Code - Run your Angular Tests in the Sidebar of Visual Studio Code
Top answer
1 of 10
73

You can debug Karma by attaching the debugger to a Chrome instance. You'd want to set your launch.json config to something like this:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "chrome",
            "request": "attach",
            "name": "Attach Karma Chrome",
            "address": "localhost",
            "port": 9333,
            "pathMapping": {
                "/": "${workspaceRoot}/",
                "/base/": "${workspaceRoot}/"
            }
        }
    ]
}

But you also need to adjust your karma.conf.js config, so that it launches Chrome instance with dev tools listening to 9333 port, like so:

browsers: [
  'ChromeDebugging'
],

customLaunchers: {
  ChromeDebugging: {
    base: 'Chrome',
    flags: [ '--remote-debugging-port=9333' ]
  }
},

With such setup you can just run your karma server (with captured browser), and then start debugging in visual studio.

If you'd like to find more details I made a tutorial on debugging Karma with Visual Studio Code.

2 of 10
36

Using Angular CLI 1.7.4: With the following steps I was able to debug a hello world Angular application with Visual Studio Code:

  1. Generate a fresh HelloWorld project:

    ng new HelloWorld

  2. Open the project in Visual Studio Code

    code HelloWorld

  3. Create a new Debug configuration:

  4. A .vscode/launch.json file is generated and opened. Replace its content by the following:

{
    // 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": "Karma Tests",
            "sourceMaps": true,
            "webRoot": "${workspaceRoot}",
            "url": "http://localhost:9876/debug.html",
            // "runtimeArgs": [
            //     "--headless"
            // ],
            "pathMapping": {
                "/": "${workspaceRoot}",
                "/base/": "${workspaceRoot}/"
            },
            "sourceMapPathOverrides": {
                "webpack:///./*": "${webRoot}/*",
                "webpack:///src/*": "${webRoot}/*",
                "webpack:///*": "*",
                "webpack:///./~/*": "${webRoot}/node_modules/*",
                "meteor://app/*": "${webRoot}/*"
            }
        }
    ]
}
  1. Open karma.conf.js and perform the following change:

  2. Open a terminal and start karma tests:

    ng test

  3. Open app.component.spec.ts and set a break point:

  4. Select "Karma Tests" in the debug menu:

  5. Press F5 to start debugging. VSCode should stop at the breakpoint:

🌐
Stack Overflow
stackoverflow.com › questions › 46025419 › how-to-debug-a-angular-4-unit-tests-using-visual-studio-code
How to debug a Angular 4 unit tests using Visual Studio Code
Then on the debug window hit f12 and then on sources tab open you spec file (ts)via "Ctrl+o". Put breakpoint and run tests again(f5). You should be able to hit breakpoints ... Ok,, I have done that before.
Find elsewhere
Top answer
1 of 6
71

Update for Angular version 9

The source files have been moved but you can still debug this way if you do the following steps

  • In devtools, select the sources tab
  • Press CTRL + P
  • Type in the name of the file you want to debug

Valid for versions below 9

The other answers are completely valid answers but having been using Angular for around 18 months now I tend to do it in the browser - chrome tools!

Run ng test then f12 and find the spec file via the webpack context. Add a breakpoint(s) and refresh and it will hit said breakpoints. As per screenshot

2 of 6
48

This is what worked for me with:

  • Angular 9.0.6 + Visual Studio Code 1.43.2
  • Angular 8.2.13 + Visual Studio Code 1.39.2
  • Angular 7, Angular CLI 1.0.* and Chrome on Windows 7.

Change configuration files

In your project root directory open karma.conf.js. Right after singleRun: false add , followed by this section:

    customLaunchers: {
      ChromeDebug: {
        base: 'Chrome',
        flags: [ '--remote-debugging-port=9333' ]
      }
    }

Add configuration to .vscode/launch.json.

  • For versions 8.* - 9.* (note "pathMapping section!):

    {
      "type": "chrome",
      "request": "attach",
      "name": "Unit tests",
      "address": "localhost",
      "port": 9333,
      "sourceMaps": true,
      "webRoot": "${workspaceFolder}",
      "pathMapping": {
        "/_karma_webpack_": "${workspaceFolder}"
      }
    },
    
  • For version 7.*:

    {
      "type": "chrome",
      "request": "attach",
      "name": "Unit tests",
      "address": "localhost",
      "port": 9333,
      "sourceMaps": true,
      "webRoot": "${workspaceFolder}"
    },
    

Start debugging

  1. Run ng test --browsers ChromeDebug

  2. Wait for Chrome browser to start. You will see something like this in command line:

    01 06 2017 16:07:29.276:INFO [launcher]: Launching browser ChromeDebug with unlimited concurrency
    
  3. Set the breakpoint in one of your .spec.ts files.

  4. In Visual Studio Code choose Unit tests debug configuration and hit F5 ("Start Debugging" button).

  5. Press Shift+Ctrl+F5 or refresh the Chrome window to rerun the tests and hit the breakpoint.


For convenience

You can also modify your package.json and add a new script:

"test-debug": "ng test --browsers ChromeDebug",

Then next time you want to start ng test with debugging just run:

npm run test-debug

References:

  • Debugging Jasmine Unit tests running with Karma runner in VS Code
  • Debugging Karma tests with VSCode
  • Angular CLI 8.1.3 Debug Unit Tests configuration - Unverified breakpoint
  • microsoft/vscode-recipes - Chrome Debugging with Angular CLI
🌐
Medium
medium.com › nextfaze › debug-angular-10-karma-tests-in-vscode-9685b0565e8
Debug Angular 12 Karma Tests in VSCode | by Zak Barbuto | NextFaze | Medium
October 4, 2021 - Run your Angular tests however you like — either via ng test in the terminal and then run the “Attach to Karma” configuration or just run the the “Run test file” launch configuration with a spec test file open in the editor (note that ...
🌐
GitHub
github.com › angular › angular-cli › issues › 17488
VSCode: Debug breakpoints not working for ng test · Issue #17488 · angular/angular-cli
April 16, 2020 - { "version": "0.2.0", "configurations": ... "${workspaceFolder}" } ] } Open applications folder in Visual Studio Code and add breakpoints to any test case inside projects/admin-console/src/app/app.component.spec.ts...
Author   prabh-62
🌐
Daniel Kreider
danielk.tech › home › how-to-debug-angular-in-vs-code
How to debug Angular in VS Code (2 Easy Steps) | Daniel Kreider
So that's a quick tutorial about how to easily do debugging properly in Angular using VS Code. There's no reason to constantly write out console.log() because that's just a time waster when you can use a break-point directly in your code. ... 100+ pages with more then 30 testing examples and secrets you need to know about testing Angular apps.
🌐
Medium
medium.com › @michaelericksen_12434 › debugging-and-testing-angular-schematics-in-vs-code-8e697b73ad8c
Debugging and Testing Angular Schematics in VS Code | by Michael Ericksen | Medium
January 10, 2019 - Now that you’ve stepped through your first unit test, let’s look into how to directly debug your application code. The npm run build pre-processing task hasn’t changed, but we’ll invoke it from an additional debug configuration (make sure to run npm i @angular-devkit/schematics-cli from the command line before running this debug configuration for the first time).
🌐
GitHub
github.com › microsoft › vscode-recipes › issues › 225
Angular CLI 8.1.3 `Debug Unit Tests` configuration - Unverified breakpoint · Issue #225 · microsoft/vscode-recipes
August 1, 2019 - This is the latest master at this point: https://github.com/microsoft/vscode-recipes/tree/851693ce90da46a36a28edeb743e09b3da6b6e6f/Angular-CLI ... { "version": "0.2.0", "configurations": [ { "name": "ng test", "type": "chrome", "request": "launch", "url": "http://localhost:9876/debug.html", "webRoot": "${workspaceFolder}", "sourceMaps": true, "pathMapping": { "/_karma_webpack_": "${workspaceFolder}" }, }, ] }
🌐
YouTube
youtube.com › watch
Master Angular Debugging in VS Code | Real-World Tips, Tricks & Traps! - YouTube
🎯 Master Angular Debugging in VS Code with real-world tips, tricks, and common traps! Learn how to debug Angular applications easily inside Visual Studio Co...
Published   April 27, 2025
🌐
Reddit
reddit.com › r/angular2 › vscode debugging with angular
r/Angular2 on Reddit: VSCode Debugging with Angular
November 8, 2024 -

Hello! I am a developer whose team is moving to Angular for the rewrite of our web application. I am going through training, and wanted to test some basic debugging through VSCode. I have been having some issues: If I set a breakpoint in VSCode, the browser starts just spinning, and becomes unresponsive, requiring me to kill the browser.

A new coworker of mine, who has worked with Angular in the past, says that there is no way to step through Angular in VSCode, something that I believe to be false through reading other online developer's experiences. I was also told that I should "just use console.log instead of browser debugging capabilities." (Somewhat irrelevant, but a head-scratcher)

But, right now I am having this block with debugging Angular with VSCode. I'm using just a template app from ng New and putting a breakpoint in app.component.ts where title gets set.

I am in development mode, and I'm using msedge.

Is there anything I'm missing, or is it really impossible to debug an Angular app through VSCode? I can sometimes get breakpoints to work temporarily through the javascript debugging terminal.

🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
Karma Test Explorer (for Angular, Jasmine, and Mocha) - Visual Studio Marketplace
Extension for Visual Studio Code - View and run your Karma or Angular tests in the VS Code Testing side bar
Top answer
1 of 12
210

Tested with Angular 5 / CLI 1.5.5

  1. Install the Chrome Debugger Extension
  2. Create the launch.json (inside .vscode folder)
  3. Use my launch.json (see below)
  4. Create the tasks.json (inside .vscode folder)
  5. Use my tasks.json (see below)
  6. Press CTRL+SHIFT+B
  7. Press F5

launch.json for angular/cli >= 1.3

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Launch Chrome",
      "type": "chrome",
      "request": "launch",
      "url": "http://localhost:4200/#",
      "webRoot": "${workspaceFolder}"
    },
    {
      "name": "Attach Chrome",
      "type": "chrome",
      "request": "attach",
      "url": "http://localhost:4200/#",
      "webRoot": "${workspaceFolder}"
    },
    {
      "name": "Launch Chrome (Test)",
      "type": "chrome",
      "request": "launch",
      "url": "http://localhost:9876/debug.html",
      "webRoot": "${workspaceFolder}"
    },
    {
      "name": "Launch Chrome (E2E)",
      "type": "node",
      "request": "launch",
      "program": "${workspaceFolder}/node_modules/protractor/bin/protractor",
      "protocol": "inspector",
      "args": ["${workspaceFolder}/protractor.conf.js"]
    }
  ]
}

tasks.json for angular/cli >= 1.3

{
    "version": "2.0.0",
    "tasks": [
      {
        "identifier": "ng serve",
        "type": "npm",
        "script": "start",
        "problemMatcher": [],
        "group": {
          "kind": "build",
          "isDefault": true
        }
      },
      {
        "identifier": "ng test",
        "type": "npm",
        "script": "test",
        "problemMatcher": [],
        "group": {
          "kind": "test",
          "isDefault": true
        }
      }
    ]
  }

Tested with Angular 2.4.8

  1. Install the Chrome Debugger Extension
  2. Create the launch.json
  3. Use my launch.json (see below)
  4. Start the NG Live Development Server (ng serve)
  5. Press F5

launch.json for angular/cli >= 1.0.0-beta.32

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "chrome",
      "request": "launch",
      "name": "Launch Chrome",
      "url": "http://localhost:4200",
      "webRoot": "${workspaceFolder}",
      "sourceMaps": true,
      "userDataDir": "${workspaceFolder}/.vscode/chrome",
      "runtimeArgs": [
        "--disable-session-crashed-bubble"
      ]
    },
    {
      "name": "Attach Chrome",
      "type": "chrome",
      "request": "attach",
      "url": "http://localhost:4200",
      "port": 9222,
      "webRoot": "${workspaceFolder}",
      "sourceMaps": true
    }
  ]
}

launch.json for angular/cli < 1.0.0-beta.32

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Lunch Chrome",
      "type": "chrome",
      "request": "launch",
      "url": "http://localhost:4200",
      "webRoot": "${workspaceFolder}/src/app",
      "sourceMaps": true,
      "sourceMapPathOverrides": {
        "webpack:///./~/*": "${workspaceFolder}/node_modules/*",
        "webpack:///./src/*": "${workspaceFolder}/src/*"
      },
      "userDataDir": "${workspaceFolder}/.vscode/chrome",
      "runtimeArgs": [
        "--disable-session-crashed-bubble"
      ]
    },
    {
      "name": "Attach Chrome",
      "type": "chrome",
      "request": "attach",
      "url": "http://localhost:4200",
      "port": 9222,
      "webRoot": "${workspaceFolder}/src/app",
      "sourceMaps": true,
      "sourceMapPathOverrides": {
        "webpack:///./~/*": "${workspaceFolder}/node_modules/*",
        "webpack:///./src/*": "${workspaceFolder}/src/*"
      }
    }
  ]
}
2 of 12
63

Looks like the VS Code team is now storing debugging recipes.

https://github.com/Microsoft/vscode-recipes/tree/master/Angular-CLI

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Launch Chrome with ng serve",
      "type": "chrome",
      "request": "launch",
      "url": "http://localhost:4200",
      "webRoot": "${workspaceRoot}"
    },
    {
      "name": "Launch Chrome with ng test",
      "type": "chrome",
      "request": "launch",
      "url": "http://localhost:9876/debug.html",
      "webRoot": "${workspaceRoot}"
    },
    {
      "name": "Launch ng e2e",
      "type": "node",
      "request": "launch",
      "program": "${workspaceRoot}/node_modules/protractor/bin/protractor",
      "protocol": "inspector",
      "args": ["${workspaceRoot}/protractor.conf.js"]
    }      
  ]
}
🌐
Angular
v17.angular.io › guide › test-debugging
Angular
Angular is a platform for building mobile and desktop web applications. Join the community of millions of developers who build compelling user interfaces with Angular.