I am using Angular CLI and VS code 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?
I am using Angular CLI and VS code 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?
In the new release of VSCode (1.14.0) they follow this recipe:
You can debug the Angular App entirely ( including the unit tests ), the recipe is straightforward.
Just to add to the other answers:
ng test
.ng test
from the drop down.This is what worked for me with Angular CLI 1.0.* and Chrome on Windows 7.
Change configuration files
In your project root directory open
karma.conf.js
. Right aftersingleRun: false
add,
followed by this section:Add configuration to
.vscode/launch.json
:Start debugging
Run
ng test --browsers ChromeDebug
Wait for Chrome browser to start. You will see something like this in command line:
Set the breakpoint in one of your
.spec.ts
files.In Visual Studio Code choose
Unit tests
debug configuration and hit F5 ("Start Debugging" button).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:
Then next time you want to start
ng test
with debugging just run:References:
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