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';

1010

import {fakeAsync, flushMicrotasks, TestBed, tick} from '@angular/core/testing';

1111

import {Subject} from 'rxjs';

1212

import {filter, take} from 'rxjs/operators';

@@ -21,6 +21,7 @@ describe('ServiceWorkerModule', () => {

2121

return;

2222

}

232324+

let errorHandlerSpy: jasmine.Spy;

2425

let swRegisterSpy: jasmine.Spy;

25262627

const untilStable = () => {

@@ -34,9 +35,14 @@ describe('ServiceWorkerModule', () => {

34353536

describe('register()', () => {

3637

const configTestBed = async (opts: SwRegistrationOptions) => {

38+

const errorHandler = {handleError: () => {}};

39+

errorHandlerSpy = spyOn(errorHandler, 'handleError');

3740

TestBed.configureTestingModule({

3841

imports: [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

});

41474248

await untilStable();

@@ -71,12 +77,10 @@ describe('ServiceWorkerModule', () => {

7177

});

72787379

it('catches and a logs registration errors', async () => {

74-

const consoleErrorSpy = spyOn(console, 'error');

7580

swRegisterSpy.and.returnValue(Promise.reject('no reason'));

76817782

await 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