1
-
2
1
import {
3
2
RX_RENDER_STRATEGIES_CONFIG ,
4
3
RxStrategyCredentials ,
5
- RxStrategyProvider
4
+ RxStrategyProvider ,
6
5
} from '@rx-angular/cdk/render-strategies' ;
7
6
import { map , tap } from 'rxjs/operators' ;
8
7
import { Promise as unpatchedPromise } from '@rx-angular/cdk/zone-less/browser' ;
9
8
import { PushModule } from '../push.module' ;
10
9
import { PushPipe } from '../push.pipe' ;
11
10
import { ComponentFixture , TestBed } from '@angular/core/testing' ;
12
11
import { ChangeDetectorRef , Component } from '@angular/core' ;
13
- import { asapScheduler , EMPTY , from , NEVER , Observable , of , scheduled , share , shareReplay , timer } from 'rxjs' ;
12
+ import {
13
+ asapScheduler ,
14
+ EMPTY ,
15
+ from ,
16
+ NEVER ,
17
+ Observable ,
18
+ of ,
19
+ scheduled ,
20
+ share ,
21
+ shareReplay ,
22
+ timer ,
23
+ } from 'rxjs' ;
14
24
import { mockConsole } from '@test-helpers' ;
15
25
16
26
function wrapWithSpace ( str : string ) : string {
17
27
return ' ' + str + ' ' ;
18
28
}
19
29
20
30
@Component ( {
21
- template : ` {{ (value$ | push: strategy | json) || 'undefined' }} ` ,
31
+ template : ` {{ (value$ | push : strategy | json) || 'undefined' }} ` ,
22
32
} )
23
33
class PushPipeTestComponent {
24
34
value$ : Observable < number > = of ( 42 ) ;
@@ -36,22 +46,25 @@ let strategyProvider: RxStrategyProvider;
36
46
const setupPushPipeComponent = ( ) => {
37
47
TestBed . configureTestingModule ( {
38
48
declarations : [ PushPipeTestComponent ] ,
39
- imports : [ PushModule ] ,
49
+ imports : [ PushPipe ] ,
40
50
providers : [
41
51
ChangeDetectorRef ,
42
52
{
43
53
provide : RX_RENDER_STRATEGIES_CONFIG ,
44
54
useValue : {
45
55
primaryStrategy : 'native' ,
46
56
customStrategies : {
47
- ' custom' : {
57
+ custom : {
48
58
name : 'custom' ,
49
- work : cdRef => {
59
+ work : ( cdRef ) => {
50
60
cdRef . detectChanges ( ) ;
51
61
} ,
52
- behavior : ( { work } ) => o$ => o$ . pipe ( tap ( ( ) => work ( ) ) )
53
- }
54
- }
62
+ behavior :
63
+ ( { work } ) =>
64
+ ( o$ ) =>
65
+ o$ . pipe ( tap ( ( ) => work ( ) ) ) ,
66
+ } ,
67
+ } ,
55
68
} ,
56
69
} ,
57
70
] ,
@@ -138,7 +151,7 @@ describe('PushPipe used as pipe in the template', () => {
138
151
const strategy = strategyProvider . strategies [ 'custom' ] ;
139
152
pushPipeTestComponent . strategy = 'custom' ;
140
153
cdSpy = jest . spyOn ( strategy , 'work' ) ;
141
- } )
154
+ } ) ;
142
155
143
156
it ( 'should not detect changes with sync value' , ( ) => {
144
157
fixturePushPipeTestComponent . detectChanges ( ) ;
@@ -147,36 +160,40 @@ describe('PushPipe used as pipe in the template', () => {
147
160
} ) ;
148
161
149
162
it ( 'should detect changes with async value' , async ( ) => {
150
- const value$ = new Observable ( sub => {
163
+ const value$ = new Observable ( ( sub ) => {
151
164
Promise . resolve ( ) . then ( ( ) => {
152
165
sub . next ( 44 ) ;
153
166
sub . complete ( ) ;
154
167
} ) ;
155
168
return ( ) => {
156
169
sub . complete ( ) ;
157
- }
170
+ } ;
158
171
} ) ;
159
172
pushPipeTestComponent . value$ = value$ ;
160
173
fixturePushPipeTestComponent . detectChanges ( ) ;
161
- expect ( componentNativeElement . textContent ) . toBe ( wrapWithSpace ( 'undefined' ) ) ;
174
+ expect ( componentNativeElement . textContent ) . toBe (
175
+ wrapWithSpace ( 'undefined' )
176
+ ) ;
162
177
await Promise . resolve ( ) ;
163
178
expect ( cdSpy ) . toBeCalledTimes ( 1 ) ;
164
179
expect ( componentNativeElement . textContent ) . toBe ( wrapWithSpace ( '44' ) ) ;
165
180
} ) ;
166
181
167
182
it ( 'should detect changes with unpatched Promise' , async ( ) => {
168
- const value$ = new Observable ( sub => {
183
+ const value$ = new Observable ( ( sub ) => {
169
184
unpatchedPromise . resolve ( ) . then ( ( ) => {
170
185
sub . next ( 44 ) ;
171
186
sub . complete ( ) ;
172
187
} ) ;
173
188
return ( ) => {
174
189
sub . complete ( ) ;
175
- }
190
+ } ;
176
191
} ) ;
177
192
pushPipeTestComponent . value$ = value$ ;
178
193
fixturePushPipeTestComponent . detectChanges ( ) ;
179
- expect ( componentNativeElement . textContent ) . toBe ( wrapWithSpace ( 'undefined' ) ) ;
194
+ expect ( componentNativeElement . textContent ) . toBe (
195
+ wrapWithSpace ( 'undefined' )
196
+ ) ;
180
197
await unpatchedPromise . resolve ( ) ;
181
198
expect ( cdSpy ) . toBeCalledTimes ( 1 ) ;
182
199
expect ( componentNativeElement . textContent ) . toBe ( wrapWithSpace ( '44' ) ) ;
@@ -186,7 +203,9 @@ describe('PushPipe used as pipe in the template', () => {
186
203
const value$ = timer ( 0 , asapScheduler ) . pipe ( map ( ( ) => 44 ) ) ;
187
204
pushPipeTestComponent . value$ = value$ ;
188
205
fixturePushPipeTestComponent . detectChanges ( ) ;
189
- expect ( componentNativeElement . textContent ) . toBe ( wrapWithSpace ( 'undefined' ) ) ;
206
+ expect ( componentNativeElement . textContent ) . toBe (
207
+ wrapWithSpace ( 'undefined' )
208
+ ) ;
190
209
await Promise . resolve ( ) ;
191
210
expect ( cdSpy ) . toBeCalledTimes ( 1 ) ;
192
211
expect ( componentNativeElement . textContent ) . toBe ( wrapWithSpace ( '44' ) ) ;
@@ -196,13 +215,14 @@ describe('PushPipe used as pipe in the template', () => {
196
215
const value$ = timer ( 0 ) . pipe ( map ( ( ) => 44 ) ) ;
197
216
pushPipeTestComponent . value$ = value$ ;
198
217
fixturePushPipeTestComponent . detectChanges ( ) ;
199
- expect ( componentNativeElement . textContent ) . toBe ( wrapWithSpace ( 'undefined' ) ) ;
200
- await new Promise ( resolve => {
218
+ expect ( componentNativeElement . textContent ) . toBe (
219
+ wrapWithSpace ( 'undefined' )
220
+ ) ;
221
+ await new Promise ( ( resolve ) => {
201
222
setTimeout ( resolve ) ;
202
- } )
223
+ } ) ;
203
224
expect ( cdSpy ) . toBeCalledTimes ( 1 ) ;
204
225
expect ( componentNativeElement . textContent ) . toBe ( wrapWithSpace ( '44' ) ) ;
205
226
} ) ;
206
-
207
- } )
227
+ } ) ;
208
228
} ) ;
0 commit comments