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

Answer from 72GM on Stack Overflow
🌐
Angular
angular.dev › cli › test
ng test • Angular
Specifies the reporters to use during test execution. Each reporter can be a string representing its name, or a tuple containing the name and an options object. Built-in reporters include 'default', 'verbose', 'dots', 'json', 'junit', 'tap', 'tap-flat', and 'html'.
🌐
Stack Overflow
stackoverflow.com › questions › 71775547 › how-to-get-more-verbose-output-from-ng-test-configuration
angular - How to get more verbose output from "ng test" configuration - Stack Overflow
Finally got past my problem by using ng-cli to bootstrap a new project and isolating one simple spec file to run there (had around 120 tests in a project that used Angular4 and angular-seed).
🌐
TutorialsPoint
tutorialspoint.com › angular_cli › angular_cli_ng_test.htm
Angular CLI − ng test Command
If you have multiple Angular projects in a workspace, you can specify which project tests to run. options: Various flags or configurations you can use to modify the behavior of the command. Note! You can also use its shorthand form "ng t", where "t" stands for "test".
🌐
GitHub
github.com › angular › angular-cli › issues › 9757
[Documentation Request] ng test --log-level options · Issue #9757 · angular/angular-cli
February 23, 2018 - On the page here I am unable to actually find any log levels. My Googling has failed me when I tried to find any information on the subject. Desired behavior What would like to see implemented + what did you expect to see: The values ava...
Author   DinoSourcesRex
🌐
Angular
v17.angular.io › cli › test
ng test
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.
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
47

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
🌐
Testing-angular
testing-angular.com › debugging-tests
Debugging tests – Testing Angular
February 17, 2021 - In this case, you can instruct ng test to consider only the file you are currently working on.
Find elsewhere
🌐
GitHub
github.com › angular › angular-cli › issues › 1246
ng test logging · Issue #1246 · angular/angular-cli
June 29, 2016 - ng test --watch=false --build=false · to external file? so that I can parse the file in TeamCity and fail the build. I tried below · ng test --watch=false --build=false > log.txt · but it only write True in it. It would be good to have full output in a file like ·
Author   kamran-pervaiz
🌐
W3Resource
w3resource.com › angular › ng-test.php
Angular - ng test - w3resource
Runs unit tests in a project. ng test <project> [options] ng t <project> [options]
🌐
YouTube
youtube.com › watch
24. Testing Angular Application using ng test command and pass all the tests - Angular CLI - YouTube
In this video we will see how to test the Angular application using ng test command and pass all the tests in the application - Angular CLI.If you like my vi...
Published   December 14, 2021
🌐
GitHub
github.com › nrwl › nx › issues › 4160
--verbose option not taken into account for test commands · Issue #4160 · nrwl/nx
November 26, 2020 - Current Behavior using the nx console or by manually using the cli, passing --verbose flag to a test command like nx run lib:test --verbose or nx run lib:test -- --verbose. running jest --verbose i...
Author   timbakkum
🌐
Automation Panda
automationpanda.com › 2018 › 01 › 15 › missing-error-messages-with-angular-testing
Missing Error Messages with Angular Testing | Automation Panda
January 18, 2018 - I recently had a devil of a time figuring out why my Angular unit tests were broken because error messages were not being printed! Running "ng test --sourcemaps=false" solved the problem.
🌐
Angular
v17.angular.io › guide › test-debugging
Debugging tests
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.
🌐
npm
npmjs.com › package › ng-test-utils
ng-test-utils - npm
March 28, 2015 - ng-test utils is now tang. You should switch the dependencies in all your builds now. Cleaner, less verbose tests for your Angular app!
      » npm install ng-test-utils
    
Published   Mar 28, 2015
Version   0.0.19
Author   James Talmage
🌐
CodeBurst
codeburst.io › angular-6-ng-test-with-jest-in-3-minutes-b1fe5ed3417c
Angular CLI: “ng test” with Jest in 3 minutes | by Jenia Barabanov | codeburst
May 21, 2022 - Today I’m going to show you how to setup your Angular CLI workspace to work with Jest while keeping it clear of boilerplate code.
🌐
Angular
docs.angular.lat › guide › testing
Visión general • Angular
✓ src/app/app.spec.ts (3) ✓ AppComponent should create the app ✓ AppComponent should have as title 'my-app' ✓ AppComponent should render title Test Files 1 passed (1) Tests 3 passed (3) Start at 18:18:01 Duration 2.46s (transform 615ms, setup 2ms, collect 2.21s, tests 5ms) El comando ng test también observa cambios.
🌐
GitHub
github.com › angular › angular-cli › issues › 10485
ng test not working after upgrade to 6.0.0 · Issue #10485 · angular/angular-cli
April 27, 2018 - 10 silly lifecycle myproj-web@0.0.1~test: Args: [ '/d /s /c', 'ng test' ] 11 silly lifecycle myproj-web@0.0.1~test: Returned: code: 1 signal: null 12 info lifecycle myproj-web@0.0.1~test: Failed to exec test script 13 verbose stack Error: myproj-web@0.0.1 test: `ng test` 13 verbose stack Exit ...
Author   DominicBoettger