11import {
22 ChangeDetectorRef ,
33 Component ,
4+ Directive ,
45 TemplateRef ,
56 ViewContainerRef ,
67} from '@angular/core' ;
@@ -13,6 +14,7 @@ import {
1314 waitForAsync ,
1415} from '@angular/core/testing' ;
1516import {
17+ BehaviorSubject ,
1618 EMPTY ,
1719 interval ,
1820 NEVER ,
@@ -60,6 +62,29 @@ class LetDirectiveTestCompleteComponent {
6062 value$ : Observable < number > = of ( 42 ) ;
6163}
6264
65+ @Directive ( {
66+ selector : '[recursiveDirective]' ,
67+ } )
68+ export class RecursiveDirective {
69+ constructor ( private subject : BehaviorSubject < number > ) {
70+ this . subject . next ( 1 ) ;
71+ }
72+ }
73+
74+ @Component ( {
75+ template : `
76+ <ng-container recursiveDirective *ngrxLet="subject as value">{{
77+ value
78+ }}</ng-container>
79+ ` ,
80+ } )
81+ class LetDirectiveTestRecursionComponent {
82+ constructor ( public subject : BehaviorSubject < number > ) { }
83+ get value$ ( ) {
84+ return this . subject ;
85+ }
86+ }
87+
6388let fixtureLetDirectiveTestComponent : ComponentFixture < LetDirectiveTestComponent > ;
6489let letDirectiveTestComponent : {
6590 value$ : ObservableInput < any > | undefined | null ;
@@ -117,6 +142,29 @@ const setupLetDirectiveTestComponentComplete = (): void => {
117142 componentNativeElement = fixtureLetDirectiveTestComponent . nativeElement ;
118143} ;
119144
145+ const setupLetDirectiveTestRecursionComponent = ( ) : void => {
146+ const subject = new BehaviorSubject ( 0 ) ;
147+ TestBed . configureTestingModule ( {
148+ declarations : [
149+ LetDirectiveTestRecursionComponent ,
150+ RecursiveDirective ,
151+ LetDirective ,
152+ ] ,
153+ providers : [
154+ { provide : ChangeDetectorRef , useClass : MockChangeDetectorRef } ,
155+ TemplateRef ,
156+ ViewContainerRef ,
157+ { provide : BehaviorSubject , useValue : subject } ,
158+ ] ,
159+ } ) ;
160+ fixtureLetDirectiveTestComponent = TestBed . createComponent (
161+ LetDirectiveTestRecursionComponent
162+ ) ;
163+ letDirectiveTestComponent =
164+ fixtureLetDirectiveTestComponent . componentInstance ;
165+ componentNativeElement = fixtureLetDirectiveTestComponent . nativeElement ;
166+ } ;
167+
120168describe ( 'LetDirective' , ( ) => {
121169 describe ( 'when nexting values' , ( ) => {
122170 beforeEach ( waitForAsync ( setupLetDirectiveTestComponent ) ) ;
@@ -281,4 +329,14 @@ describe('LetDirective', () => {
281329 expect ( componentNativeElement . textContent ) . toBe ( 'true' ) ;
282330 } ) ;
283331 } ) ;
332+
333+ describe ( 'when rendering recursively' , ( ) => {
334+ beforeEach ( waitForAsync ( setupLetDirectiveTestRecursionComponent ) ) ;
335+
336+ it ( 'should render 2nd emitted value if the observable emits while the view is being rendered' , fakeAsync ( ( ) => {
337+ fixtureLetDirectiveTestComponent . detectChanges ( ) ;
338+ expect ( letDirectiveTestComponent ) . toBeDefined ( ) ;
339+ expect ( componentNativeElement . textContent ) . toBe ( '1' ) ;
340+ } ) ) ;
341+ } ) ;
284342} ) ;
0 commit comments