@@ -10,7 +10,7 @@ import {AsyncPipe, NgFor} from '@angular/common';
1010import { ElementSchemaRegistry } from '@angular/compiler/src/schema/element_schema_registry' ;
1111import { TEST_COMPILER_PROVIDERS } from '@angular/compiler/test/test_bindings' ;
1212import { MockSchemaRegistry } from '@angular/compiler/testing' ;
13- import { AfterContentChecked , AfterContentInit , AfterViewChecked , AfterViewInit , ChangeDetectionStrategy , ChangeDetectorRef , Component , DebugElement , Directive , DoCheck , Injectable , Input , OnChanges , OnDestroy , OnInit , Output , Pipe , PipeTransform , RenderComponentType , Renderer , RootRenderer , SimpleChange , SimpleChanges , TemplateRef , Type , ViewContainerRef , WrappedValue , forwardRef } from '@angular/core' ;
13+ import { AfterContentChecked , AfterContentInit , AfterViewChecked , AfterViewInit , ChangeDetectionStrategy , ChangeDetectorRef , Component , ComponentMetadata , DebugElement , Directive , DoCheck , Injectable , Input , OnChanges , OnDestroy , OnInit , Output , Pipe , PipeTransform , RenderComponentType , Renderer , RootRenderer , SimpleChange , SimpleChanges , TemplateRef , Type , ViewContainerRef , WrappedValue , forwardRef } from '@angular/core' ;
1414import { DebugDomRenderer } from '@angular/core/src/debug/debug_renderer' ;
1515import { ViewMetadata } from '@angular/core/src/metadata/view' ;
1616import { ComponentFixture , TestBed , fakeAsync , flushMicrotasks , tick } from '@angular/core/testing' ;
@@ -25,26 +25,26 @@ import {BaseException} from '../../src/facade/exceptions';
2525import { NumberWrapper , isBlank } from '../../src/facade/lang' ;
2626
2727export function main ( ) {
28- let tcb : TestComponentBuilder ;
2928 let elSchema : MockSchemaRegistry ;
3029 let renderLog : RenderLog ;
3130 let directiveLog : DirectiveLog ;
3231
3332 function createCompFixture < T > ( template : string ) : ComponentFixture < TestComponent > ;
3433 function createCompFixture < T > ( template : string , compType : Type < T > ) : ComponentFixture < T > ;
3534 function createCompFixture < T > (
36- template : string , compType : Type < T > , _tcb : TestComponentBuilder ) : ComponentFixture < T > ;
37- function createCompFixture < T > (
38- template : string , compType : Type < T > = < any > TestComponent ,
39- _tcb : TestComponentBuilder = null ) : ComponentFixture < T > {
40- if ( isBlank ( _tcb ) ) {
41- _tcb = tcb ;
42- }
43- return _tcb
44- . overrideView (
45- compType ,
46- new ViewMetadata ( { template : template , directives : ALL_DIRECTIVES , pipes : ALL_PIPES } ) )
47- . createFakeAsync ( compType ) ;
35+ template : string , compType : Type < T > = < any > TestComponent ) : ComponentFixture < T > {
36+ TestBed . overrideComponent ( compType , { set : new ComponentMetadata ( { template} ) } ) ;
37+
38+ initHelpers ( ) ;
39+
40+ return TestBed . createComponent ( compType ) ;
41+ }
42+
43+ function initHelpers ( ) : void {
44+ elSchema = TestBed . get ( ElementSchemaRegistry ) ;
45+ renderLog = TestBed . get ( RenderLog ) ;
46+ directiveLog = TestBed . get ( DirectiveLog ) ;
47+ elSchema . existingProperties [ 'someProp' ] = true ;
4848 }
4949
5050 function queryDirs ( el : DebugElement , dirType : Type < any > ) : any {
@@ -81,24 +81,36 @@ export function main() {
8181 beforeEach ( ( ) => {
8282 TestBed . configureCompiler ( { providers : TEST_COMPILER_PROVIDERS } ) ;
8383 TestBed . configureTestingModule ( {
84+ declarations : [
85+ TestData ,
86+ TestDirective ,
87+ TestComponent ,
88+ AnotherComponent ,
89+ TestLocals ,
90+ CompWithRef ,
91+ EmitterDirective ,
92+ PushComp ,
93+ OrderCheckDirective2 ,
94+ OrderCheckDirective0 ,
95+ OrderCheckDirective1 ,
96+ Gh9882 ,
97+ Uninitialized ,
98+ Person ,
99+ PersonHolder ,
100+ PersonHolderHolder ,
101+ CountingPipe ,
102+ CountingImpurePipe ,
103+ MultiArgPipe ,
104+ PipeWithOnDestroy ,
105+ IdentityPipe ,
106+ WrappedPipe ,
107+ ] ,
84108 providers :
85109 [ RenderLog , DirectiveLog , { provide : RootRenderer , useClass : LoggingRootRenderer } ]
86110 } ) ;
87111 } ) ;
88112
89- beforeEach ( fakeAsync ( inject (
90- [ TestComponentBuilder , ElementSchemaRegistry , RenderLog , DirectiveLog ] ,
91- ( _tcb : TestComponentBuilder , _elSchema : MockSchemaRegistry , _renderLog : RenderLog ,
92- _directiveLog : DirectiveLog ) => {
93- tcb = _tcb ;
94- elSchema = _elSchema ;
95- renderLog = _renderLog ;
96- directiveLog = _directiveLog ;
97- elSchema . existingProperties [ 'someProp' ] = true ;
98- } ) ) ) ;
99-
100113 describe ( 'expressions' , ( ) => {
101-
102114 it ( 'should support literals' ,
103115 fakeAsync ( ( ) => { expect ( _bindAndCheckSimpleValue ( 10 ) ) . toEqual ( [ 'someProp=10' ] ) ; } ) ) ;
104116
@@ -646,10 +658,16 @@ export function main() {
646658
647659 describe ( 'lifecycle' , ( ) => {
648660 function createCompWithContentAndViewChild ( ) : ComponentFixture < any > {
661+ TestBed . overrideComponent ( AnotherComponent , {
662+ set : new ComponentMetadata ( {
663+ selector : 'other-cmp' ,
664+ template : '<div testDirective="viewChild"></div>' ,
665+ } )
666+ } ) ;
667+
649668 return createCompFixture (
650669 '<div testDirective="parent"><div *ngIf="true" testDirective="contentChild"></div><other-cmp></other-cmp></div>' ,
651- TestComponent ,
652- tcb . overrideTemplate ( AnotherComponent , '<div testDirective="viewChild"></div>' ) ) ;
670+ TestComponent ) ;
653671 }
654672
655673 describe ( 'ngOnInit' , ( ) => {
@@ -752,7 +770,6 @@ export function main() {
752770 it ( 'should be called after processing the content children but before the view children' ,
753771 fakeAsync ( ( ) => {
754772 var ctx = createCompWithContentAndViewChild ( ) ;
755-
756773 ctx . detectChanges ( false ) ;
757774
758775 expect ( directiveLog . filter ( [ 'ngDoCheck' , 'ngAfterContentInit' ] ) ) . toEqual ( [
@@ -989,11 +1006,15 @@ export function main() {
9891006 } ) ) ;
9901007
9911008 it ( 'should be called after processing the content and view children' , fakeAsync ( ( ) => {
1009+ TestBed . overrideComponent ( AnotherComponent , {
1010+ set : new ComponentMetadata (
1011+ { selector : 'other-cmp' , template : '<div testDirective="viewChild"></div>' } )
1012+ } ) ;
1013+
9921014 var ctx = createCompFixture (
9931015 '<div testDirective="parent"><div *ngFor="let x of [0,1]" testDirective="contentChild{{x}}"></div>' +
9941016 '<other-cmp></other-cmp></div>' ,
995- TestComponent ,
996- tcb . overrideTemplate ( AnotherComponent , '<div testDirective="viewChild"></div>' ) ) ;
1017+ TestComponent ) ;
9971018
9981019 ctx . detectChanges ( false ) ;
9991020 ctx . destroy ( ) ;
@@ -1029,9 +1050,11 @@ export function main() {
10291050 } ) ) ;
10301051
10311052 it ( 'should call ngOnDestroy on an injectable class' , fakeAsync ( ( ) => {
1032- var ctx = createCompFixture (
1033- '<div testDirective="dir"></div>' , TestComponent ,
1034- tcb . overrideProviders ( TestDirective , [ InjectableWithLifecycle ] ) ) ;
1053+ TestBed . overrideDirective (
1054+ TestDirective , { set : { providers : [ InjectableWithLifecycle ] } } ) ;
1055+
1056+ var ctx = createCompFixture ( '<div testDirective="dir"></div>' , TestComponent ) ;
1057+
10351058 ctx . debugElement . children [ 0 ] . injector . get ( InjectableWithLifecycle ) ;
10361059 ctx . detectChanges ( false ) ;
10371060
@@ -1143,31 +1166,6 @@ export function main() {
11431166 } ) ;
11441167}
11451168
1146- const ALL_DIRECTIVES = [
1147- forwardRef ( ( ) => TestDirective ) ,
1148- forwardRef ( ( ) => TestComponent ) ,
1149- forwardRef ( ( ) => AnotherComponent ) ,
1150- forwardRef ( ( ) => TestLocals ) ,
1151- forwardRef ( ( ) => CompWithRef ) ,
1152- forwardRef ( ( ) => EmitterDirective ) ,
1153- forwardRef ( ( ) => PushComp ) ,
1154- forwardRef ( ( ) => OrderCheckDirective2 ) ,
1155- forwardRef ( ( ) => OrderCheckDirective0 ) ,
1156- forwardRef ( ( ) => OrderCheckDirective1 ) ,
1157- forwardRef ( ( ) => Gh9882 ) ,
1158- NgFor ,
1159- ] ;
1160-
1161- const ALL_PIPES = [
1162- forwardRef ( ( ) => CountingPipe ) ,
1163- forwardRef ( ( ) => CountingImpurePipe ) ,
1164- forwardRef ( ( ) => MultiArgPipe ) ,
1165- forwardRef ( ( ) => PipeWithOnDestroy ) ,
1166- forwardRef ( ( ) => IdentityPipe ) ,
1167- forwardRef ( ( ) => WrappedPipe ) ,
1168- AsyncPipe ,
1169- ] ;
1170-
11711169@Injectable ( )
11721170class RenderLog {
11731171 log : string [ ] = [ ] ;
@@ -1268,23 +1266,21 @@ class MultiArgPipe implements PipeTransform {
12681266 }
12691267}
12701268
1271- @Component ( { selector : 'test-cmp' , template : '' , directives : ALL_DIRECTIVES , pipes : ALL_PIPES } )
1269+ @Component ( { selector : 'test-cmp' , template : 'empty' } )
12721270class TestComponent {
12731271 value : any ;
12741272 a : any ;
12751273 b : any ;
12761274}
12771275
1278- @Component ( { selector : 'other-cmp' , directives : ALL_DIRECTIVES , pipes : ALL_PIPES , template : '' } )
1276+ @Component ( { selector : 'other-cmp' , template : 'empty ' } )
12791277class AnotherComponent {
12801278}
12811279
12821280@Component ( {
12831281 selector : 'comp-with-ref' ,
12841282 template : '<div (event)="noop()" emitterDirective></div>{{value}}' ,
1285- host : { 'event' : 'noop()' } ,
1286- directives : ALL_DIRECTIVES ,
1287- pipes : ALL_PIPES
1283+ host : { 'event' : 'noop()' }
12881284} )
12891285class CompWithRef {
12901286 @Input ( ) public value : any ;
@@ -1298,8 +1294,6 @@ class CompWithRef {
12981294 selector : 'push-cmp' ,
12991295 template : '<div (event)="noop()" emitterDirective></div>{{value}}{{renderIncrement}}' ,
13001296 host : { '(event)' : 'noop()' } ,
1301- directives : ALL_DIRECTIVES ,
1302- pipes : ALL_PIPES ,
13031297 changeDetection : ChangeDetectionStrategy . OnPush
13041298} )
13051299class PushComp {
@@ -1459,7 +1453,7 @@ class TestLocals {
14591453 }
14601454}
14611455
1462- @Component ( { selector : 'root' } )
1456+ @Component ( { selector : 'root' , template : 'emtpy' } )
14631457class Person {
14641458 age : number ;
14651459 name : string ;
@@ -1504,17 +1498,17 @@ class Address {
15041498 toString ( ) : string { return this . city || '-' ; }
15051499}
15061500
1507- @Component ( { selector : 'root' } )
1501+ @Component ( { selector : 'root' , template : 'empty' } )
15081502class Uninitialized {
15091503 value : any = null ;
15101504}
15111505
1512- @Component ( { selector : 'root' } )
1506+ @Component ( { selector : 'root' , template : 'empty' } )
15131507class TestData {
15141508 public a : any ;
15151509}
15161510
1517- @Component ( { selector : 'root' } )
1511+ @Component ( { selector : 'root' , template : 'empty' } )
15181512class TestDataWithGetter {
15191513 public fn : Function ;
15201514
@@ -1525,10 +1519,10 @@ class Holder<T> {
15251519 value : T ;
15261520}
15271521
1528- @Component ( { selector : 'root' } )
1522+ @Component ( { selector : 'root' , template : 'empty' } )
15291523class PersonHolder extends Holder < Person > {
15301524}
15311525
1532- @Component ( { selector : 'root' } )
1526+ @Component ( { selector : 'root' , template : 'empty' } )
15331527class PersonHolderHolder extends Holder < Holder < Person > > {
15341528}
0 commit comments