fix(service-worker): handle error with ErrorHandler (#39990) · angular/angular@588dbd3
@@ -6,7 +6,7 @@
66 * found in the LICENSE file at https://angular.io/license
77 */
889-import {ApplicationRef, PLATFORM_ID} from '@angular/core';
9+import {ApplicationRef, ErrorHandler, PLATFORM_ID} from '@angular/core';
1010import {fakeAsync, flushMicrotasks, TestBed, tick} from '@angular/core/testing';
1111import {Subject} from 'rxjs';
1212import {filter, take} from 'rxjs/operators';
@@ -21,6 +21,7 @@ describe('ServiceWorkerModule', () => {
2121return;
2222}
232324+let errorHandlerSpy: jasmine.Spy;
2425let swRegisterSpy: jasmine.Spy;
25262627const untilStable = () => {
@@ -34,9 +35,14 @@ describe('ServiceWorkerModule', () => {
34353536describe('register()', () => {
3637const configTestBed = async (opts: SwRegistrationOptions) => {
38+const errorHandler = {handleError: () => {}};
39+errorHandlerSpy = spyOn(errorHandler, 'handleError');
3740TestBed.configureTestingModule({
3841imports: [ServiceWorkerModule.register('sw.js', opts)],
39-providers: [{provide: PLATFORM_ID, useValue: 'browser'}],
42+providers: [
43+{provide: ErrorHandler, useValue: errorHandler},
44+{provide: PLATFORM_ID, useValue: 'browser'},
45+],
4046});
41474248await untilStable();
@@ -71,12 +77,10 @@ describe('ServiceWorkerModule', () => {
7177});
72787379it('catches and a logs registration errors', async () => {
74-const consoleErrorSpy = spyOn(console, 'error');
7580swRegisterSpy.and.returnValue(Promise.reject('no reason'));
76817782await configTestBed({enabled: true, scope: 'foo'});
78-expect(consoleErrorSpy)
79-.toHaveBeenCalledWith('Service worker registration failed with:', 'no reason');
83+expect(errorHandlerSpy).toHaveBeenCalledWith('no reason');
8084});
8185});
8286