66 * found in the LICENSE file at https://angular.io/license
77 */
88
9- 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}
2323
24+ let errorHandlerSpy :jasmine . Spy ;
2425let swRegisterSpy :jasmine . Spy ;
2526
2627const untilStable = ( ) => {
@@ -34,9 +35,14 @@ describe('ServiceWorkerModule', () => {
3435
3536describe ( '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} ) ;
4147
4248await untilStable ( ) ;
@@ -71,12 +77,10 @@ describe('ServiceWorkerModule', () => {
7177} ) ;
7278
7379it ( 'catches and a logs registration errors' , async ( ) => {
74- const consoleErrorSpy = spyOn ( console , 'error' ) ;
7580swRegisterSpy . and . returnValue ( Promise . reject ( 'no reason' ) ) ;
7681
7782await 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