Debug tests in NG test

I use Angular CLI and VS code, but none of my breakpoints in my specification files seem to get hit when running ng test?

Do I need to make some adjustments?

+25
source share
5 answers

The rest of the answers are completely correct answers, but, using Angular for about 18 months, I try to do this in the browser - Chrome tools!

Run ng test, then f12 and find the spec file through the web package context. Add breakpoint (s) and refresh and it will reach the specified breakpoints. According to the screenshot

enter image description here

+25
source

VSCode (1.14.0) recipe:

Angular ( ), .

+13

, Angular CLI 1.0. * Chrome Windows 7.


karma.conf.js. singleRun: false , :

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

.vscode/launch.json:

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

  1. ng test --browsers ChromeDebug

  2. Chrome. - :

    01 06 2017 16:07:29.276:INFO [launcher]: Launching browser ChromeDebug with unlimited concurrency
    
  3. .spec.ts .spec.ts.

  4. Visual Studio Code Unit tests F5 ( " ").

  5. Shift+Ctrl+F5 Chrome, .


package.json :

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

, ng test , :

npm run test-debug

:

+11

:

  • @titusfx.
  • ng test.
  • Visual Studio ng test .
  • You may need to update your browser if you cannot reach breakpoints for the first time.

enter image description here

+3
source

You can simply add a "debugger" where you want to debug and run

ng test

When the Chrome browser opens, turn on the developer tools and it will stop on your "debugger".

0
source

Source: https://habr.com/ru/post/1017175/


All Articles