Repository: angular
Issue: beforeEach is swallowing ngChanges exceptions
Labels: area: zones,P3

# 🐞 bug report

### Affected Package

Something related to Karma tests.


### Is this a regression?

Not sure, I found this issue first in Angular 11.2.1 and while making the repro I validated it also happens in version 11.0.9.

### Description

I found a case in which Angular swallows exceptions thrown from inside the `ngOnChanges` method when running inside of a test. But only if the exception is thrown inside of a `beforeEach`.

I have this code:
```typescript
@Component({ selector: `inner`, template: `` })
class InnerComponent {
  @Input() myInput: string;
  ngOnChanges() {
    throw "Some unhandled exception";
  }
}
@Component({ template: `<inner [myInput]="someVar"></inner>` })
class TestHostComponent {
  someVar = null;
}
...
describe("Some test", () => {
  beforeEach(fakeAsync(() => {
    fixture = TestBed.createComponent(TestHostComponent);
    fixture.autoDetectChanges();
  }));

  it("does stuff", fakeAsync(() => {
    tick();
  }));
});
```

You can see that the ngOnChanges throws an exception, which is being swallowed and instead I get this:
```
Chrome 88.0.4324.182 (Linux x86_64) Some test does stuff FAILED
        Error: 1 timer(s) still in the queue.
            at UserContext.<anonymous> (node_modules/zone.js/dist/zone-testing.js:1760:1)
            at ZoneDelegate.invoke (node_modules/zone.js/dist/zone-evergreen.js:364:1)
            at ProxyZoneSpec.push.QpwO.ProxyZoneSpec.onInvoke (node_modules/zone.js/dist/zone-testing.js:292:1)
            at ZoneDelegate.invoke (node_modules/zone.js/dist/zone-evergreen.js:363:1)
            at Zone.run (node_modules/zone.js/dist/zone-evergreen.js:123:1)
            at runInTestZone (node_modules/zone.js/dist/zone-testing.js:545:1)
            at UserContext.<anonymous> (node_modules/zone.js/dist/zone-testing.js:560:1)
            at <Jasmine>
```

If I move the `beforeEach` code to the `it`:
```typescript
  it("does stuff", fakeAsync(() => {
    fixture = TestBed.createComponent(TestHostComponent);
    fixture.autoDetectChanges();
    tick();
  }));
```

Then the exception is as expected:
```
Chrome 88.0.4324.182 (Linux x86_64) Some test does stuff FAILED
        Some unhandled exception thrown
```

This makes extremely difficult debugging tests, as the timer it refers to is not one created by our custom code but some internal code in Angular or Karma.

## 🔬 Minimal Reproduction

The reproduction is here:
https://github.com/dwilches/angular-issue-repro

## 🔥 Exception or Error
```
Chrome 88.0.4324.182 (Linux x86_64) Some test does stuff FAILED
        Error: 1 timer(s) still in the queue.
            at UserContext.<anonymous> (node_modules/zone.js/dist/zone-testing.js:1760:1)
            at ZoneDelegate.invoke (node_modules/zone.js/dist/zone-evergreen.js:364:1)
            at ProxyZoneSpec.push.QpwO.ProxyZoneSpec.onInvoke (node_modules/zone.js/dist/zone-testing.js:292:1)
            at ZoneDelegate.invoke (node_modules/zone.js/dist/zone-evergreen.js:363:1)
            at Zone.run (node_modules/zone.js/dist/zone-evergreen.js:123:1)
            at runInTestZone (node_modules/zone.js/dist/zone-testing.js:545:1)
            at UserContext.<anonymous> (node_modules/zone.js/dist/zone-testing.js:560:1)
            at <Jasmine>
```



## 🌍  Your Environment

**Angular Version:**
<pre><code>

_                      _                 ____ _     ___
/ \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
/ ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
    /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
|___/


Angular CLI: 11.0.7
Node: 10.24.0
OS: linux x64

Angular: 11.0.9
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Ivy Workspace: Yes

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1100.7
@angular-devkit/build-angular   0.1100.7
@angular-devkit/core            11.0.7
@angular-devkit/schematics      11.0.7
@angular/cli                    11.0.7
@schematics/angular             11.0.7
@schematics/update              0.1100.7
rxjs                            6.6.3
typescript                      4.0.7
</code></pre>

**Anything else relevant?**
Nothing comes to mind.