1- import  {  ErrorHandler ,  Provider  }  from  '@angular/core' ; 
1+ import  {  ErrorHandler ,  Provider ,   Type  }  from  '@angular/core' ; 
22import  {  TestBed  }  from  '@angular/core/testing' ; 
33import  {  Action ,  Store  }  from  '@ngrx/store' ; 
4- import  {  Observable ,  of  }  from  'rxjs' ; 
4+ import  {  Observable ,  of ,   throwError  }  from  'rxjs' ; 
55import  {  catchError  }  from  'rxjs/operators' ; 
66import  {  createEffect ,  EFFECTS_ERROR_HANDLER ,  EffectsModule  }  from  '..' ; 
7+ import  *  as  effectsSrc  from  '../src/effects_error_handler' ; 
78
89describe ( 'Effects Error Handler' ,  ( )  =>  { 
910  let  subscriptionCount : number ; 
1011  let  globalErrorHandler : jasmine . Spy ; 
1112  let  storeNext : jasmine . Spy ; 
1213
13-   function  makeEffectTestBed ( ...providers : Provider [ ] )  { 
14+   function  makeEffectTestBed ( effect :  Type < any > ,   ...providers : Provider [ ] )  { 
1415    subscriptionCount  =  0 ; 
1516
1617    TestBed . configureTestingModule ( { 
17-       imports : [ EffectsModule . forRoot ( [ ErrorEffect ] ) ] , 
18+       imports : [ EffectsModule . forRoot ( [ effect ] ) ] , 
1819      providers : [ 
1920        { 
2021          provide : Store , 
@@ -38,8 +39,14 @@ describe('Effects Error Handler', () => {
3839    storeNext  =  store . next ; 
3940  } 
4041
42+   it ( 'should retry on infinite error up to 10 times' ,  ( )  =>  { 
43+     makeEffectTestBed ( AlwaysErrorEffect ) ; 
44+ 
45+     expect ( globalErrorHandler . calls . count ( ) ) . toBe ( 10 ) ; 
46+   } ) ; 
47+ 
4148  it ( 'should retry and notify error handler when effect error handler is not provided' ,  ( )  =>  { 
42-     makeEffectTestBed ( ) ; 
49+     makeEffectTestBed ( ErrorEffect ) ; 
4350
4451    // two subscriptions expected: 
4552    // 1. Initial subscription to the effect (this will error) 
@@ -62,7 +69,7 @@ describe('Effects Error Handler', () => {
6269        ) ; 
6370      } ) ; 
6471
65-     makeEffectTestBed ( { 
72+     makeEffectTestBed ( ErrorEffect ,   { 
6673      provide : EFFECTS_ERROR_HANDLER , 
6774      useValue : effectsErrorHandlerSpy , 
6875    } ) ; 
@@ -84,6 +91,10 @@ describe('Effects Error Handler', () => {
8491    } ) ; 
8592  } 
8693
94+   class  AlwaysErrorEffect  { 
95+     effect$  =  createEffect ( ( )  =>  throwError ( 'always an error' ) ) ; 
96+   } 
97+ 
8798  /** 
8899   * This observable factory returns an observable that will never emit, but the first subscriber will get an immediate 
89100   * error. All subsequent subscribers will just get an observable that does not emit. 
0 commit comments