6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
8
9
- import { ApplicationRef , PLATFORM_ID } from '@angular/core' ;
9
+ import { ApplicationRef , ErrorHandler , PLATFORM_ID } from '@angular/core' ;
10
10
import { fakeAsync , flushMicrotasks , TestBed , tick } from '@angular/core/testing' ;
11
11
import { Subject } from 'rxjs' ;
12
12
import { filter , take } from 'rxjs/operators' ;
@@ -21,6 +21,7 @@ describe('ServiceWorkerModule', () => {
21
21
return ;
22
22
}
23
23
24
+ let errorHandlerSpy : jasmine . Spy ;
24
25
let swRegisterSpy : jasmine . Spy ;
25
26
26
27
const untilStable = ( ) => {
@@ -34,9 +35,14 @@ describe('ServiceWorkerModule', () => {
34
35
35
36
describe ( 'register()' , ( ) => {
36
37
const configTestBed = async ( opts : SwRegistrationOptions ) => {
38
+ const errorHandler = { handleError : ( ) => { } } ;
39
+ errorHandlerSpy = spyOn ( errorHandler , 'handleError' ) ;
37
40
TestBed . configureTestingModule ( {
38
41
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
+ ] ,
40
46
} ) ;
41
47
42
48
await untilStable ( ) ;
@@ -71,12 +77,10 @@ describe('ServiceWorkerModule', () => {
71
77
} ) ;
72
78
73
79
it ( 'catches and a logs registration errors' , async ( ) => {
74
- const consoleErrorSpy = spyOn ( console , 'error' ) ;
75
80
swRegisterSpy . and . returnValue ( Promise . reject ( 'no reason' ) ) ;
76
81
77
82
await configTestBed ( { enabled : true , scope : 'foo' } ) ;
78
- expect ( consoleErrorSpy )
79
- . toHaveBeenCalledWith ( 'Service worker registration failed with:' , 'no reason' ) ;
83
+ expect ( errorHandlerSpy ) . toHaveBeenCalledWith ( 'no reason' ) ;
80
84
} ) ;
81
85
} ) ;
82
86
0 commit comments