diff --git a/packages/service-worker/src/module.ts b/packages/service-worker/src/module.ts index 0bc5e92c0c..5f147181a6 100644 --- a/packages/service-worker/src/module.ts +++ b/packages/service-worker/src/module.ts @@ -7,7 +7,7 @@ */ import {isPlatformBrowser} from '@angular/common'; -import {APP_INITIALIZER, ApplicationRef, ErrorHandler, InjectionToken, Injector, ModuleWithProviders, NgModule, NgZone, PLATFORM_ID} from '@angular/core'; +import {APP_INITIALIZER, ApplicationRef, InjectionToken, Injector, ModuleWithProviders, NgModule, NgZone, PLATFORM_ID} from '@angular/core'; import {merge, Observable, of} from 'rxjs'; import {delay, filter, take} from 'rxjs/operators'; @@ -128,10 +128,9 @@ export function ngswAppInitializer( const ngZone = injector.get(NgZone); ngZone.runOutsideAngular( () => readyToRegister$.pipe(take(1)).subscribe( - () => navigator.serviceWorker.register(script, {scope: options.scope}).catch(err => { - const errorHandler = injector.get(ErrorHandler); - errorHandler.handleError(err); - }))); + () => + navigator.serviceWorker.register(script, {scope: options.scope}) + .catch(err => console.error('Service worker registration failed with:', err)))); }; return initializer; } diff --git a/packages/service-worker/test/module_spec.ts b/packages/service-worker/test/module_spec.ts index 42c5cb73a0..bb46214f32 100644 --- a/packages/service-worker/test/module_spec.ts +++ b/packages/service-worker/test/module_spec.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {ApplicationRef, ErrorHandler, PLATFORM_ID} from '@angular/core'; +import {ApplicationRef, PLATFORM_ID} from '@angular/core'; import {fakeAsync, flushMicrotasks, TestBed, tick} from '@angular/core/testing'; import {Subject} from 'rxjs'; import {filter, take} from 'rxjs/operators'; @@ -21,7 +21,6 @@ describe('ServiceWorkerModule', () => { return; } - let errorHandlerSpy: jasmine.Spy; let swRegisterSpy: jasmine.Spy; const untilStable = () => { @@ -35,14 +34,9 @@ describe('ServiceWorkerModule', () => { describe('register()', () => { const configTestBed = async (opts: SwRegistrationOptions) => { - const errorHandler = {handleError: () => {}}; - errorHandlerSpy = spyOn(errorHandler, 'handleError'); TestBed.configureTestingModule({ imports: [ServiceWorkerModule.register('sw.js', opts)], - providers: [ - {provide: ErrorHandler, useValue: errorHandler}, - {provide: PLATFORM_ID, useValue: 'browser'}, - ], + providers: [{provide: PLATFORM_ID, useValue: 'browser'}], }); await untilStable(); @@ -77,10 +71,12 @@ describe('ServiceWorkerModule', () => { }); it('catches and a logs registration errors', async () => { + const consoleErrorSpy = spyOn(console, 'error'); swRegisterSpy.and.returnValue(Promise.reject('no reason')); await configTestBed({enabled: true, scope: 'foo'}); - expect(errorHandlerSpy).toHaveBeenCalledWith('no reason'); + expect(consoleErrorSpy) + .toHaveBeenCalledWith('Service worker registration failed with:', 'no reason'); }); });