title: Detect console errors as error and make test fail
body: <p>Is it possible to detect console errors in unit tests with karma runner and mark the unit test case as failed. In my current project I have hundreds of tests and the project isn't in a clean state. When I run the unit tests with <code>ng test</code> I get hundreds or maybe even thousands of console message like</p>
  <pre><code>ERROR: ''mat-icon' is not a known element:
  1. If 'mat-icon' is an Angular component, then verify that it is part of this module.
  2. If 'mat-icon' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.'
  </code></pre>
  <p>but all test cases pass successfully. There is no hint which test cases cause these problems. I tried to manually step through the tests by replacing <code>it(</code> with <code>fit(</code>, check each test and fix it but it takes too long. I'd like to make each test fail that contains an error in the console log like it can be done in E2E tests with</p>
  <pre><code>afterEach(async () =&gt; {
    // Assert that there are no errors emitted from the browser
    const logs = await browser.manage().logs().get(logging.Type.BROWSER);
    expect(logs).not.toContain(jasmine.objectContaining({
      level: logging.Level.SEVERE,
    } as logging.Entry));
  });
  </code></pre>
  <p>so that the CD/CI pipeline fails and the developer has to fix the tests.</p>
  <p>The configuration of the unit tests is the default. It's the karma runner with jasmine and a headless Chrome.</p>
  <p>I searched the karma configuration but couldn't find it. Is this even possible with unit tests? If it's possible, is it possible to configure this at one place and not to touch all hundreds of test files?</p>
  <p>To reproduce my problem create a new Angular project with <code>ng new sandbox</code>. Change the <code>app.component.ts</code> to</p>
  <pre><code>import { Component } from '@angular/core';
  
  @Component({
    selector: 'my-app',
    template: '&lt;mat-icon&gt;&lt;/mat-icon&gt;'
  })
  export class AppComponent  {
  }
  </code></pre>
  <p>Change the <code>app.component.spec.ts</code> to:</p>
  <pre><code>import { TestBed } from '@angular/core/testing';
  import { AppComponent } from './app.component';
  
  describe('AppComponent', () =&gt; {
    beforeEach(async () =&gt; {
      await TestBed.configureTestingModule({
        declarations: [
          AppComponent
        ],
      }).compileComponents();
    });
  
    it('should create the app', () =&gt; {
      const fixture = TestBed.createComponent(AppComponent);
      const app = fixture.componentInstance;
      expect(app).toBeTruthy();
    });
  });
  
  </code></pre>
  <p>Delete <code>app.components.html</code> and <code>app.component.css</code>. Run <code>ng test</code>.</p>
  <p>Even though the app doesn't work because Material isn't installed the test won't fail. It passes but it prints error logs. I get the output:</p>
  <pre><code>&gt; ng test
  
  ⠋ Generating browser application bundles...21 04 2021 18:18:06.826:WARN [karma]: No captured browser, open http://localhost:9876/
  21 04 2021 18:18:06.830:INFO [karma-server]: Karma v6.1.2 server started at http://localhost:9876/
  21 04 2021 18:18:06.831:INFO [launcher]: Launching browsers Chrome with concurrency unlimited
  ⠙ Generating browser application bundles (phase: building)...21 04 2021 18:18:06.835:INFO [launcher]: Starting browser Chrome
  ✔ Browser application bundle generation complete.
  21 04 2021 18:18:09.656:WARN [karma]: No captured browser, open http://localhost:9876/
  21 04 2021 18:18:09.696:INFO [Chrome 89.0.4389.114 (Linux x86_64)]: Connected on socket w7tUMYWxN3pJ5tdBAAAB with id 77883839
  ERROR: 'NG0304: 'mat-icon' is not a known element:
  1. If 'mat-icon' is an Angular component, then verify that it is part of this module.
  2. If 'mat-icon' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.'
  Chrome 89.0.4389.114 (Linux x86_64): Executed 0 of 1 SUCCESS (0 secs / 0 secs)
  ERROR: 'NG0304: 'mat-icon' is not a known element:
  1. If 'mat-icon' is an Angular component, then verify that it is part of this module.
  Chrome 89.0.4389.114 (Linux x86_64): Executed 1 of 1 SUCCESS (0.072 secs / 0.023 secs)
  TOTAL: 1 SUCCESS
  </code></pre>
  <p>I'd like this test to fail.</p>