1
+ import { ChangeDetectorRef , Component , ViewContainerRef } from '@angular/core' ;
1
2
import { ComponentFixture , TestBed } from '@angular/core/testing' ;
2
3
import { html } from 'lit-html' ;
3
4
import { AsyncDirective , directive } from 'lit/async-directive.js' ;
@@ -13,22 +14,34 @@ class ToLowerAsyncDirective extends AsyncDirective {
13
14
protected override disconnected ( ) : void {
14
15
directiveLog . push ( 'disconnected' ) ;
15
16
}
16
- }
17
- export const toLowerAsync = directive ( ToLowerAsyncDirective ) ;
17
+ }
18
+ export const toLowerAsync = directive ( ToLowerAsyncDirective ) ;
19
+
20
+ @Component ( {
21
+ selector : 'igx-test-template-wrapper' ,
22
+ templateUrl : './wrapper.component.html' ,
23
+ styleUrls : [ './wrapper.component.scss' ] ,
24
+ imports : [ ]
25
+ } )
26
+ class TestTemplateWrapperComponent extends TemplateWrapperComponent {
27
+ constructor ( public viewContainerRef : ViewContainerRef , public _cdr : ChangeDetectorRef ) {
28
+ super ( _cdr ) ;
29
+ }
30
+ }
18
31
19
32
describe ( 'WrapperComponent' , ( ) => {
20
- let component : TemplateWrapperComponent ;
21
- let fixture : ComponentFixture < TemplateWrapperComponent > ;
33
+ let component : TestTemplateWrapperComponent ;
34
+ let fixture : ComponentFixture < TestTemplateWrapperComponent > ;
22
35
23
36
beforeEach ( async ( ) => {
24
37
await TestBed . configureTestingModule ( {
25
- imports : [ TemplateWrapperComponent ]
38
+ imports : [ TestTemplateWrapperComponent ]
26
39
} )
27
40
. compileComponents ( ) ;
28
41
} ) ;
29
42
30
43
beforeEach ( ( ) => {
31
- fixture = TestBed . createComponent ( TemplateWrapperComponent ) ;
44
+ fixture = TestBed . createComponent ( TestTemplateWrapperComponent ) ;
32
45
component = fixture . componentInstance ;
33
46
fixture . detectChanges ( ) ;
34
47
} ) ;
@@ -41,6 +54,7 @@ describe('WrapperComponent', () => {
41
54
const context = { text : "Oh hi" } ;
42
55
const templateRef = component . addTemplate ( ( ctx ) => html `< span id ="template1 "> ${ ctx . text } </ span > ` ) ;
43
56
const embeddedView = templateRef . createEmbeddedView ( context ) ;
57
+ component . viewContainerRef . insert ( embeddedView ) ;
44
58
embeddedView . detectChanges ( ) ;
45
59
46
60
const span = embeddedView . rootNodes [ 0 ] . querySelector ( "#template1" ) ;
@@ -53,6 +67,7 @@ describe('WrapperComponent', () => {
53
67
const context = { text : "OH HI" } ;
54
68
const templateRef = component . addTemplate ( ( ctx ) => html `< span id ="template1 "> ${ toLowerAsync ( ctx . text ) } </ span > ` ) ;
55
69
const embeddedView = templateRef . createEmbeddedView ( context ) ;
70
+ component . viewContainerRef . insert ( embeddedView ) ;
56
71
embeddedView . detectChanges ( ) ;
57
72
58
73
const span = embeddedView . rootNodes [ 0 ] . querySelector ( "#template1" ) ;
0 commit comments