66 * found in the LICENSE file at https://angular.io/license
77 */
88
9- import { NgFor } from '@angular/common' ;
10- import { Component , ContentChildren , Directive , Inject , QueryList , asNativeElements , forwardRef } from '@angular/core' ;
11- import { AsyncTestCompleter , TestComponentBuilder , beforeEach , ddescribe , describe , iit , inject , it , xit } from '@angular/core/testing/testing_internal ' ;
9+ import { CommonModule } from '@angular/common' ;
10+ import { Component , ContentChildren , Directive , Inject , NgModule , QueryList , asNativeElements , forwardRef } from '@angular/core' ;
11+ import { TestBed } from '@angular/core/testing' ;
1212import { expect } from '@angular/platform-browser/testing/matchers' ;
1313
1414export function main ( ) {
1515 describe ( 'forwardRef integration' , function ( ) {
16- it ( 'should instantiate components which are declared using forwardRef' ,
17- inject (
18- [ TestComponentBuilder , AsyncTestCompleter ] ,
19- ( tcb : TestComponentBuilder , async : AsyncTestCompleter ) => {
20- tcb . createAsync ( App ) . then ( ( tc ) => {
21- tc . detectChanges ( ) ;
22- expect ( asNativeElements ( tc . debugElement . children ) ) . toHaveText ( 'frame(lock)' ) ;
23- async . done ( ) ;
24- } ) ;
25- } ) ) ;
16+ beforeEach ( ( ) => { TestBed . configureTestingModule ( { imports : [ Module ] , declarations : [ App ] } ) ; } ) ;
17+
18+ it ( 'should instantiate components which are declared using forwardRef' , ( ) => {
19+ const a = TestBed . createComponent ( App ) ;
20+ a . detectChanges ( ) ;
21+ expect ( asNativeElements ( a . debugElement . children ) ) . toHaveText ( 'frame(lock)' ) ;
22+ expect ( TestBed . get ( ModuleFrame ) ) . toBeDefined ( ) ;
23+ } ) ;
2624 } ) ;
2725}
2826
27+ @NgModule ( {
28+ imports : [ CommonModule ] ,
29+ providers : [ forwardRef ( ( ) => ModuleFrame ) ] ,
30+ declarations : [ forwardRef ( ( ) => Door ) , forwardRef ( ( ) => Lock ) ] ,
31+ exports : [ forwardRef ( ( ) => Door ) , forwardRef ( ( ) => Lock ) ]
32+ } )
33+ class Module {
34+ }
35+
2936@Component ( {
3037 selector : 'app' ,
3138 viewProviders : [ forwardRef ( ( ) => Frame ) ] ,
3239 template : `<door><lock></lock></door>` ,
33- directives : [ forwardRef ( ( ) => Door ) , forwardRef ( ( ) => Lock ) ] ,
3440} )
3541class App {
3642}
3743
3844@Component ( {
3945 selector : 'lock' ,
40- directives : [ NgFor ] ,
4146 template : `{{frame.name}}(<span *ngFor="let lock of locks">{{lock.name}}</span>)` ,
4247} )
4348class Door {
@@ -51,6 +56,10 @@ class Frame {
5156 name : string = 'frame' ;
5257}
5358
59+ class ModuleFrame {
60+ name : string = 'moduleFram' ;
61+ }
62+
5463@Directive ( { selector : 'lock' } )
5564class Lock {
5665 name : string = 'lock' ;
0 commit comments