How do I prevent a Browser from opening up when I run Angular unit tests?

When you run unit tests using the Angular CLI's ng test command you'll often see a browser open up. Sometimes this is useful if you want to debug the unit tests in the browser, however since I have moved the bulk of my unit test debugging to IntelliJ, this is just a minor annoyance.

You can shut it off. Open up the Karma.conf.js file in the src folder of your Angular CLI project. Find this line:

view plain print about
1browsers: ['Chrome'],

This tells Karma to open Chrome to run the tests. But, there is another option:

view plain print about
1browsers: ['ChromeHeadless'],

Rerun your tests and you'll find that no browser opens up.

I love it when things are easy.

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)

Comments are not allowed for this entry.