The level of logging by karma can be changed in the karma.conf.js file.

Go to karma.conf.js and add/change the property logLevel to config.LOG_DISABLE if you don't want to see any logs or config.LOG_ERROR if you want to only see the errors. Like this:

module.exports = function (config) {
  config.set({
    ...,
    logLevel: config.LOG_ERROR,
    ...,
  })
}

If you are running karma from the command line you can append --log-level debug to the command for the same effect.

Answer from Tom on Stack Overflow
🌐
GitHub
github.com › angular › angular-cli › issues › 1246
ng test logging · Issue #1246 · angular/angular-cli
June 29, 2016 - 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 · ng test --watch=false --build=false --output=path\log.txt ·
Author   kamran-pervaiz
🌐
Stack Overflow
stackoverflow.com › questions › 48502563 › how-to-log-ng-command-output-in-proper-format
windows - How to log ng command output in proper format? - Stack Overflow
I am trying to log output for the following commands ng build -prod > build.log and ng test > test.log. But the content in log files is partially unreadable format. [33m29 01 2018 08:16:38.574:
Discussions

[Documentation Request] ng test --log-level options
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 + wh... More on github.com
🌐 github.com
6
February 23, 2018
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
July 13, 2018
angular - NG Test show names in console - Stack Overflow
I'm referring here to when all tests pass but the console is reporting errors. ... don't you just love the people that downvote but aren't big enough to add a comment... this is a perfectly reasonable question and if you'd been in this situation you'd understand why ... I am in this situation years later. Does anyone has a solution for this? Like the logs to show the spec file ... More on stackoverflow.com
🌐 stackoverflow.com
Generate Unit test reports for an Angular Project
I have an Angular project hosted on GitLab and I’m trying to generate Unit test reports via the CI Pipeline. I’m following this guide https://docs.gitlab.com/ee/ci/unit_test_reports.html There is no Angular example in the docs, that’s why I’m kindy stuck and don’t really know how ... More on forum.gitlab.com
🌐 forum.gitlab.com
8
0
September 9, 2020
🌐
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.
🌐
GitHub
github.com › angular › angular-cli › issues › 9757
[Documentation Request] ng test --log-level options · Issue #9757 · angular/angular-cli
February 23, 2018 - What would like to see implemented + what did you expect to see: The values available for the --log-level option
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
🌐
Ng-log
ng-log.github.io › ng-log › 0.8.0 › logging
Logging - ng-log
The DFATAL severity logs a FATAL error in debug mode (i.e., there is no NDEBUG macro defined), but avoids halting the program in production by automatically reducing the severity to ERROR. Unless otherwise specified, ng-log uses the format · <tmp>/<program name>.<hostname>.<user name>.log.<severity level>.<date>-<time>.<pid> for log filenames written to a directory designated as <tmp> and determined according to the following rules.
Find elsewhere
🌐
Angular
docs.angular.lat › cli › test
ng test • Angular
Enables debugging mode for tests, allowing the use of the Node Inspector. ... Specifies glob patterns of files to exclude from testing, relative to the project root.
🌐
TutorialsPoint
tutorialspoint.com › angular_cli › angular_cli_ng_test.htm
Angular CLI − ng test Command
Home Whiteboard Practice Code Graphing Calculator Online Compilers Articles Tools ... Python TechnologiesDatabasesComputer ProgrammingWeb DevelopmentJava TechnologiesComputer ScienceMobile DevelopmentBig Data & AnalyticsMicrosoft TechnologiesDevOpsLatest TechnologiesMachine LearningDigital MarketingSoftware QualityManagement Tutorials View All Categories ... This chapter will discuss the Angular CLI ng test command, including its syntax, arguments, and options.
🌐
syslog-ng
syslog-ng.com › community › b › blog › posts › developing-a-syslog-ng-configuration
Developing a syslog-ng configuration - Blog - syslog-ng Community - syslog-ng Community
This configuration is concluded ... destination. You can easily test this configuration by starting syslog-ng with it and sending a few test messages using the logger command....
🌐
Automation Panda
automationpanda.com › 2018 › 01 › 15 › missing-error-messages-with-angular-testing
Missing Error Messages with Angular Testing | Automation Panda
January 18, 2018 - The workaround is to add the “–sourcemaps=false” option to the “ng test” command. If the package.json file contains a “test” script that calls “ng test”, the option may be added there.
🌐
Pluralsight
pluralsight.com › tech insights & how-to guides › tech guides & tutorials
Executing Unit Tests Using the Angular CLI | Pluralsight
August 27, 2020 - Apart from this named argument, the ng test CLI command has a number of other options at your disposal. Below, you can find a breakdown of some of the most useful options: browsers: This option allows you to specify directly the browsers you want to run your unit tests within · codeCoverage: A boolean indicating whether or not you want a full, code coverage report generated for this unit testing run · include: This very useful option allows you to specify globbed file ...