fix(core): unsubscribe from the `onError` when the root view is remov… · angular/angular@35309bb

Original file line numberDiff line numberDiff line change

@@ -6,7 +6,7 @@

66

* found in the LICENSE file at https://angular.io/license

77

*/

88
9-

import {ApplicationRef, COMPILER_OPTIONS, Component, destroyPlatform, NgModule, TestabilityRegistry, ViewEncapsulation} from '@angular/core';

9+

import {ApplicationRef, COMPILER_OPTIONS, Component, destroyPlatform, NgModule, NgZone, TestabilityRegistry, ViewEncapsulation} from '@angular/core';

1010

import {expect} from '@angular/core/testing/src/testing_internal';

1111

import {BrowserModule} from '@angular/platform-browser';

1212

import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';

@@ -227,6 +227,22 @@ describe('bootstrap', () => {

227227

}));

228228

});

229229
230+

describe('PlatformRef cleanup', () => {

231+

it('should unsubscribe from `onError` when Injector is destroyed',

232+

withBody('<my-app></my-app>', async () => {

233+

const TestModule = createComponentAndModule();

234+
235+

const ngModuleRef = await platformBrowserDynamic().bootstrapModule(TestModule);

236+

const ngZone = ngModuleRef.injector.get(NgZone);

237+
238+

expect(ngZone.onError.observers.length).toBe(1);

239+
240+

ngModuleRef.destroy();

241+
242+

expect(ngZone.onError.observers.length).toBe(0);

243+

}));

244+

});

245+
230246

onlyInIvy('options cannot be changed in Ivy').describe('changing bootstrap options', () => {

231247

beforeEach(() => {

232248

spyOn(console, 'error');

@@ -365,4 +381,4 @@ export class MultipleSelectorsAppComponent {

365381

bootstrap: [MultipleSelectorsAppComponent],

366382

})

367383

export class MultipleSelectorsAppModule {

368-

}

384+

}