1
1
import { Component , ErrorHandler } from '@angular/core' ;
2
2
import { TestBed } from '@angular/core/testing' ;
3
3
import { BehaviorSubject , EMPTY , Observable , throwError , map , tap } from 'rxjs' ;
4
- import { RxEffects } from './../src/lib/ effects.service' ;
4
+ import { RxEffects } from './effects.service' ;
5
5
6
6
// tslint:disable: max-classes-per-file
7
7
@@ -21,29 +21,23 @@ const selector3 = (state: TState) => `${state}3`;
21
21
const selector4 = ( state : TState ) => `${ state } 4` ;
22
22
23
23
class Service {
24
- method1 ( ..._ : any [ ] ) : void {
25
- }
24
+ method1 ( ..._ : any [ ] ) : void { }
26
25
27
- method2 ( ..._ : any [ ] ) : void {
28
- }
26
+ method2 ( ..._ : any [ ] ) : void { }
29
27
30
- method3 ( ..._ : any [ ] ) : void {
31
- }
28
+ method3 ( ..._ : any [ ] ) : void { }
32
29
33
- method4 ( ..._ : any [ ] ) : void {
34
- }
30
+ method4 ( ..._ : any [ ] ) : void { }
35
31
36
- method4OnError ( ..._ : any [ ] ) : void {
37
- }
32
+ method4OnError ( ..._ : any [ ] ) : void { }
38
33
39
- method4OnComplete ( ..._ : any [ ] ) : void {
40
- }
34
+ method4OnComplete ( ..._ : any [ ] ) : void { }
41
35
}
42
36
43
37
// tslint:disable-next-line: prefer-on-push-component-change-detection use-component-selector
44
38
@Component ( {
45
39
template : '' ,
46
- providers : [ RxEffects ]
40
+ providers : [ RxEffects ] ,
47
41
} )
48
42
class TestComponent {
49
43
constructor ( store : Store , service : Service , effects : RxEffects ) {
@@ -53,30 +47,32 @@ class TestComponent {
53
47
effects . register ( store . select ( selector4 ) , {
54
48
next : service . method4 ,
55
49
error : service . method4OnError ,
56
- complete : service . method4OnComplete
50
+ complete : service . method4OnComplete ,
57
51
} ) ;
58
52
}
59
53
}
60
54
61
55
// tslint:disable-next-line: prefer-on-push-component-change-detection use-component-selector
62
56
@Component ( {
63
57
template : '' ,
64
- providers : [ RxEffects ]
58
+ providers : [ RxEffects ] ,
65
59
} )
66
60
class TestUntilEffectComponent {
67
61
constructor ( store : Store , service : Service , private effects : RxEffects ) {
68
- const effectId1 = effects . register ( store . select ( ( v ) => v === 'effectTrigger' ) , ( ) => void 0 ) ;
69
- store . state$ . pipe (
70
- effects . untilEffect ( effectId1 )
71
- ) . subscribe ( service . method1 ) ;
72
-
62
+ const effectId1 = effects . register (
63
+ store . select ( ( v ) => v === 'effectTrigger' ) ,
64
+ ( ) => void 0
65
+ ) ;
66
+ store . state$
67
+ . pipe ( effects . untilEffect ( effectId1 ) )
68
+ . subscribe ( service . method1 ) ;
73
69
}
74
70
}
75
71
76
72
// tslint:disable-next-line: prefer-on-push-component-change-detection use-component-selector
77
73
@Component ( {
78
74
template : '' ,
79
- providers : [ RxEffects ]
75
+ providers : [ RxEffects ] ,
80
76
} )
81
77
class TestOnDestroyComponent {
82
78
constructor ( store : Store , service : Service , private effects : RxEffects ) {
@@ -87,7 +83,7 @@ class TestOnDestroyComponent {
87
83
// tslint:disable-next-line: prefer-on-push-component-change-detection use-component-selector
88
84
@Component ( {
89
85
template : '' ,
90
- providers : [ RxEffects ]
86
+ providers : [ RxEffects ] ,
91
87
} )
92
88
class TestUnregisterComponent {
93
89
private readonly effectId1 : number ;
@@ -123,11 +119,11 @@ describe('RxEffects', () => {
123
119
method1 : jest . fn ( ) ,
124
120
method2 : jest . fn ( ) ,
125
121
method3 : jest . fn ( ) ,
126
- method4 : jest . fn ( )
122
+ method4 : jest . fn ( ) ,
127
123
} ;
128
124
await TestBed . configureTestingModule ( {
129
125
declarations : [ TestComponent ] ,
130
- providers : [ Store , { provide : Service , useValue : service } ]
126
+ providers : [ Store , { provide : Service , useValue : service } ] ,
131
127
} ) . compileComponents ( ) ;
132
128
TestBed . createComponent ( TestComponent ) ;
133
129
const store = TestBed . inject ( Store ) ;
@@ -152,11 +148,11 @@ describe('RxEffects', () => {
152
148
method1 : jest . fn ( ) ,
153
149
method2 : jest . fn ( ) ,
154
150
method3 : jest . fn ( ) ,
155
- method4 : jest . fn ( )
151
+ method4 : jest . fn ( ) ,
156
152
} ;
157
153
await TestBed . configureTestingModule ( {
158
154
declarations : [ TestComponent ] ,
159
- providers : [ Store , { provide : Service , useValue : service } ]
155
+ providers : [ Store , { provide : Service , useValue : service } ] ,
160
156
} ) . compileComponents ( ) ;
161
157
const fixture = TestBed . createComponent ( TestComponent ) ;
162
158
const store = TestBed . inject ( Store ) ;
@@ -190,10 +186,10 @@ describe('RxEffects', () => {
190
186
} ,
191
187
method2 : jest . fn ( ) ,
192
188
method3 : jest . fn ( ) ,
193
- method4 : jest . fn ( )
189
+ method4 : jest . fn ( ) ,
194
190
} ;
195
191
const customErrorHandler : ErrorHandler = {
196
- handleError : jest . fn ( )
192
+ handleError : jest . fn ( ) ,
197
193
} ;
198
194
await TestBed . configureTestingModule ( {
199
195
declarations : [ TestComponent ] ,
@@ -202,9 +198,9 @@ describe('RxEffects', () => {
202
198
{ provide : Service , useValue : service } ,
203
199
{
204
200
provide : ErrorHandler ,
205
- useValue : customErrorHandler
206
- }
207
- ]
201
+ useValue : customErrorHandler ,
202
+ } ,
203
+ ] ,
208
204
} ) . compileComponents ( ) ;
209
205
TestBed . createComponent ( TestComponent ) ;
210
206
const store = TestBed . inject ( Store ) ;
@@ -222,19 +218,15 @@ describe('RxEffects', () => {
222
218
223
219
test ( 'should invoke complete callback upon completion' , async ( ) => {
224
220
const service = {
225
- method1 : ( ) => {
226
- } ,
227
- method2 : ( ) => {
228
- } ,
229
- method3 : ( ) => {
230
- } ,
231
- method4 : ( ) => {
232
- } ,
233
- method4OnComplete : jest . fn ( )
221
+ method1 : ( ) => { } ,
222
+ method2 : ( ) => { } ,
223
+ method3 : ( ) => { } ,
224
+ method4 : ( ) => { } ,
225
+ method4OnComplete : jest . fn ( ) ,
234
226
} ;
235
227
await TestBed . configureTestingModule ( {
236
228
declarations : [ TestComponent ] ,
237
- providers : [ Store , { provide : Service , useValue : service } ]
229
+ providers : [ Store , { provide : Service , useValue : service } ] ,
238
230
} ) . compileComponents ( ) ;
239
231
TestBed . createComponent ( TestComponent ) ;
240
232
const store = TestBed . inject ( Store ) ;
@@ -251,15 +243,11 @@ describe('RxEffects', () => {
251
243
252
244
test ( 'should invoke error callback when source observable errors' , async ( ) => {
253
245
const service = {
254
- method1 : ( ) => {
255
- } ,
256
- method2 : ( ) => {
257
- } ,
258
- method3 : ( ) => {
259
- } ,
260
- method4 : ( ) => {
261
- } ,
262
- method4OnError : jest . fn ( )
246
+ method1 : ( ) => { } ,
247
+ method2 : ( ) => { } ,
248
+ method3 : ( ) => { } ,
249
+ method4 : ( ) => { } ,
250
+ method4OnError : jest . fn ( ) ,
263
251
} ;
264
252
jest
265
253
. spyOn ( Store . prototype , 'select' )
@@ -274,12 +262,12 @@ describe('RxEffects', () => {
274
262
Store ,
275
263
{ provide : Service , useValue : service } ,
276
264
{
277
- provide : ErrorHandler , useValue : {
278
- handleError : ( ) => {
279
- }
280
- }
281
- }
282
- ]
265
+ provide : ErrorHandler ,
266
+ useValue : {
267
+ handleError : ( ) => { } ,
268
+ } ,
269
+ } ,
270
+ ] ,
283
271
} ) . compileComponents ( ) ;
284
272
TestBed . createComponent ( TestComponent ) ;
285
273
const store = TestBed . inject ( Store ) ;
@@ -294,11 +282,11 @@ describe('RxEffects', () => {
294
282
test ( 'should cancel side-effect if unregistered imperatively' , async ( ) => {
295
283
const service = {
296
284
method1 : jest . fn ( ) ,
297
- method2 : jest . fn ( )
285
+ method2 : jest . fn ( ) ,
298
286
} ;
299
287
await TestBed . configureTestingModule ( {
300
288
declarations : [ TestUnregisterComponent ] ,
301
- providers : [ Store , { provide : Service , useValue : service } ]
289
+ providers : [ Store , { provide : Service , useValue : service } ] ,
302
290
} ) . compileComponents ( ) ;
303
291
const fixture = TestBed . createComponent ( TestUnregisterComponent ) ;
304
292
const component = fixture . componentInstance ;
@@ -332,7 +320,7 @@ describe('RxEffects', () => {
332
320
} ;
333
321
await TestBed . configureTestingModule ( {
334
322
declarations : [ TestUntilEffectComponent ] ,
335
- providers : [ Store , { provide : Service , useValue : service } ]
323
+ providers : [ Store , { provide : Service , useValue : service } ] ,
336
324
} ) . compileComponents ( ) ;
337
325
const fixture = TestBed . createComponent ( TestUntilEffectComponent ) ;
338
326
const component = fixture . componentInstance ;
@@ -350,7 +338,6 @@ describe('RxEffects', () => {
350
338
store . state$ . next ( 'foo' ) ;
351
339
352
340
expect ( service . method1 ) . not . toHaveBeenCalled ( ) ;
353
-
354
341
} ) ;
355
342
356
343
test ( 'should cancel side-effect if components gets destroyed when using onDestroy' , async ( ) => {
@@ -359,7 +346,7 @@ describe('RxEffects', () => {
359
346
} ;
360
347
await TestBed . configureTestingModule ( {
361
348
declarations : [ TestOnDestroyComponent ] ,
362
- providers : [ Store , { provide : Service , useValue : service } ]
349
+ providers : [ Store , { provide : Service , useValue : service } ] ,
363
350
} ) . compileComponents ( ) ;
364
351
const fixture = TestBed . createComponent ( TestOnDestroyComponent ) ;
365
352
const component = fixture . componentInstance ;
0 commit comments