11import {
22 AsyncTestCompleter ,
3+ TestComponentBuilder ,
4+ asNativeElements ,
35 beforeEach ,
46 ddescribe ,
57 xdescribe ,
@@ -13,8 +15,6 @@ import {
1315 xit
1416} from 'angular2/test_lib' ;
1517
16- import { TestBed } from 'angular2/test' ;
17-
1818import { Injector , bind } from 'angular2/di' ;
1919import { Component , View } from 'angular2/src/core/annotations/decorators' ;
2020import * as annotations from 'angular2/src/core/annotations_impl/view' ;
@@ -37,9 +37,8 @@ var teamCmpCount;
3737export function main ( ) {
3838 describe ( 'Outlet Directive' , ( ) => {
3939
40- var ctx : MyComp ;
41- var tb : TestBed ;
42- var view , rtr , location ;
40+ var tcb : TestComponentBuilder ;
41+ var rootTC , rtr , location ;
4342
4443 beforeEachBindings ( ( ) => [
4544 Pipeline ,
@@ -52,29 +51,29 @@ export function main() {
5251 [ RouteRegistry , Pipeline , Location ] )
5352 ] ) ;
5453
55- beforeEach ( inject ( [ TestBed , Router , Location ] , ( testBed , router , loc ) => {
56- tb = testBed ;
57- ctx = new MyComp ( ) ;
54+ beforeEach ( inject ( [ TestComponentBuilder , Router , Location ] , ( tcBuilder , router , loc ) => {
55+ tcb = tcBuilder ;
5856 rtr = router ;
5957 location = loc ;
6058 teamCmpCount = 0 ;
6159 } ) ) ;
6260
6361 function compile ( template : string = "<router-outlet></router-outlet>" ) {
64- tb . overrideView (
65- MyComp ,
66- new annotations . View (
67- { template : ( '<div>' + template + '</div>' ) , directives : [ RouterOutlet , RouterLink ] } ) ) ;
68- return tb . createView ( MyComp , { context : ctx } ) . then ( ( v ) => { view = v ; } ) ;
62+ return tcb . overrideView ( MyComp , new annotations . View ( {
63+ template : ( '<div>' + template + '</div>' ) ,
64+ directives : [ RouterOutlet , RouterLink ]
65+ } ) )
66+ . createAsync ( MyComp )
67+ . then ( ( tc ) => { rootTC = tc ; } ) ;
6968 }
7069
7170 it ( 'should work in a simple case' , inject ( [ AsyncTestCompleter ] , ( async ) => {
7271 compile ( )
7372 . then ( ( _ ) => rtr . config ( { 'path' : '/test' , 'component' : HelloCmp } ) )
7473 . then ( ( _ ) => rtr . navigate ( '/test' ) )
7574 . then ( ( _ ) => {
76- view . detectChanges ( ) ;
77- expect ( view . rootNodes ) . toHaveText ( 'hello' ) ;
75+ rootTC . detectChanges ( ) ;
76+ expect ( rootTC . nativeElement ) . toHaveText ( 'hello' ) ;
7877 async . done ( ) ;
7978 } ) ;
8079 } ) ) ;
@@ -86,13 +85,13 @@ export function main() {
8685 . then ( ( _ ) => rtr . config ( { 'path' : '/user/:name' , 'component' : UserCmp } ) )
8786 . then ( ( _ ) => rtr . navigate ( '/user/brian' ) )
8887 . then ( ( _ ) => {
89- view . detectChanges ( ) ;
90- expect ( view . rootNodes ) . toHaveText ( 'hello brian' ) ;
88+ rootTC . detectChanges ( ) ;
89+ expect ( rootTC . nativeElement ) . toHaveText ( 'hello brian' ) ;
9190 } )
9291 . then ( ( _ ) => rtr . navigate ( '/user/igor' ) )
9392 . then ( ( _ ) => {
94- view . detectChanges ( ) ;
95- expect ( view . rootNodes ) . toHaveText ( 'hello igor' ) ;
93+ rootTC . detectChanges ( ) ;
94+ expect ( rootTC . nativeElement ) . toHaveText ( 'hello igor' ) ;
9695 async . done ( ) ;
9796 } ) ;
9897 } ) ) ;
@@ -103,8 +102,8 @@ export function main() {
103102 . then ( ( _ ) => rtr . config ( { 'path' : '/a/...' , 'component' : ParentCmp } ) )
104103 . then ( ( _ ) => rtr . navigate ( '/a/b' ) )
105104 . then ( ( _ ) => {
106- view . detectChanges ( ) ;
107- expect ( view . rootNodes ) . toHaveText ( 'outer { inner { hello } }' ) ;
105+ rootTC . detectChanges ( ) ;
106+ expect ( rootTC . nativeElement ) . toHaveText ( 'outer { inner { hello } }' ) ;
108107 async . done ( ) ;
109108 } ) ;
110109 } ) ) ;
@@ -116,14 +115,16 @@ export function main() {
116115 . then ( ( _ ) => rtr . config ( { 'path' : '/redirected' , 'component' : A } ) )
117116 . then ( ( _ ) => rtr . navigate ( '/original' ) )
118117 . then ( ( _ ) => {
119- view . detectChanges ( ) ;
120- expect ( view . rootNodes ) . toHaveText ( 'A' ) ;
118+ rootTC . detectChanges ( ) ;
119+ expect ( rootTC . nativeElement ) . toHaveText ( 'A' ) ;
121120 expect ( location . urlChanges ) . toEqual ( [ '/redirected' ] ) ;
122121 async . done ( ) ;
123122 } ) ;
124123 } ) ) ;
125124
126- function getHref ( view ) { return DOM . getAttribute ( view . rootNodes [ 0 ] . childNodes [ 0 ] , 'href' ) ; }
125+ function getHref ( tc ) {
126+ return DOM . getAttribute ( tc . componentViewChildren [ 0 ] . nativeElement , 'href' ) ;
127+ }
127128
128129 it ( 'should generate absolute hrefs that include the base href' ,
129130 inject ( [ AsyncTestCompleter ] , ( async ) => {
@@ -132,8 +133,8 @@ export function main() {
132133 . then ( ( _ ) => rtr . config ( { 'path' : '/user' , 'component' : UserCmp , 'as' : 'user' } ) )
133134 . then ( ( _ ) => rtr . navigate ( '/a/b' ) )
134135 . then ( ( _ ) => {
135- view . detectChanges ( ) ;
136- expect ( getHref ( view ) ) . toEqual ( '/my/base/user' ) ;
136+ rootTC . detectChanges ( ) ;
137+ expect ( getHref ( rootTC ) ) . toEqual ( '/my/base/user' ) ;
137138 async . done ( ) ;
138139 } ) ;
139140 } ) ) ;
@@ -144,8 +145,8 @@ export function main() {
144145 . then ( ( _ ) => rtr . config ( { 'path' : '/user' , 'component' : UserCmp , 'as' : 'user' } ) )
145146 . then ( ( _ ) => rtr . navigate ( '/a/b' ) )
146147 . then ( ( _ ) => {
147- view . detectChanges ( ) ;
148- expect ( getHref ( view ) ) . toEqual ( '/user' ) ;
148+ rootTC . detectChanges ( ) ;
149+ expect ( getHref ( rootTC ) ) . toEqual ( '/user' ) ;
149150 async . done ( ) ;
150151 } ) ;
151152 } ) ) ;
@@ -156,29 +157,29 @@ export function main() {
156157 . then ( ( _ ) => rtr . config ( { 'path' : '/team/:id/...' , 'component' : TeamCmp } ) )
157158 . then ( ( _ ) => rtr . navigate ( '/team/angular/user/rado' ) )
158159 . then ( ( _ ) => {
159- view . detectChanges ( ) ;
160+ rootTC . detectChanges ( ) ;
160161 expect ( teamCmpCount ) . toBe ( 1 ) ;
161- expect ( view . rootNodes ) . toHaveText ( 'team angular { hello rado }' ) ;
162+ expect ( rootTC . nativeElement ) . toHaveText ( 'team angular { hello rado }' ) ;
162163 } )
163164 . then ( ( _ ) => rtr . navigate ( '/team/angular/user/victor' ) )
164165 . then ( ( _ ) => {
165- view . detectChanges ( ) ;
166+ rootTC . detectChanges ( ) ;
166167 expect ( teamCmpCount ) . toBe ( 1 ) ;
167- expect ( view . rootNodes ) . toHaveText ( 'team angular { hello victor }' ) ;
168+ expect ( rootTC . nativeElement ) . toHaveText ( 'team angular { hello victor }' ) ;
168169 async . done ( ) ;
169170 } ) ;
170171 } ) ) ;
171172
172173
173174 it ( 'should generate link hrefs with params' , inject ( [ AsyncTestCompleter ] , ( async ) => {
174- ctx . name = 'brian' ;
175175 compile ( '<a href="hello" router-link="user" [router-params]="{name: name}">{{name}}</a>' )
176176 . then ( ( _ ) => rtr . config ( { 'path' : '/user/:name' , 'component' : UserCmp , 'as' : 'user' } ) )
177177 . then ( ( _ ) => rtr . navigate ( '/a/b' ) )
178178 . then ( ( _ ) => {
179- view . detectChanges ( ) ;
180- expect ( view . rootNodes ) . toHaveText ( 'brian' ) ;
181- expect ( DOM . getAttribute ( view . rootNodes [ 0 ] . childNodes [ 0 ] , 'href' ) )
179+ rootTC . componentInstance . name = 'brian' ;
180+ rootTC . detectChanges ( ) ;
181+ expect ( rootTC . nativeElement ) . toHaveText ( 'brian' ) ;
182+ expect ( DOM . getAttribute ( rootTC . componentViewChildren [ 0 ] . nativeElement , 'href' ) )
182183 . toEqual ( '/user/brian' ) ;
183184 async . done ( ) ;
184185 } ) ;
@@ -187,7 +188,7 @@ export function main() {
187188 describe ( 'when clicked' , ( ) => {
188189
189190 var clickOnElement = function ( view ) {
190- var anchorEl = view . rootNodes [ 0 ] . childNodes [ 0 ] ;
191+ var anchorEl = rootTC . componentViewChildren [ 0 ] . nativeElement ;
191192 var dispatchedEvent = DOM . createMouseEvent ( 'click' ) ;
192193 DOM . dispatchEvent ( anchorEl , dispatchedEvent ) ;
193194 return dispatchedEvent ;
@@ -200,9 +201,9 @@ export function main() {
200201 . then ( ( _ ) => rtr . config ( { 'path' : '/user' , 'component' : UserCmp , 'as' : 'user' } ) )
201202 . then ( ( _ ) => rtr . navigate ( '/a/b' ) )
202203 . then ( ( _ ) => {
203- view . detectChanges ( ) ;
204+ rootTC . detectChanges ( ) ;
204205
205- var dispatchedEvent = clickOnElement ( view ) ;
206+ var dispatchedEvent = clickOnElement ( rootTC ) ;
206207 expect ( dispatchedEvent . defaultPrevented || ! dispatchedEvent . returnValue )
207208 . toBe ( true ) ;
208209
@@ -221,9 +222,9 @@ export function main() {
221222 . then ( ( _ ) => rtr . config ( { 'path' : '/user' , 'component' : UserCmp , 'as' : 'user' } ) )
222223 . then ( ( _ ) => rtr . navigate ( '/a/b' ) )
223224 . then ( ( _ ) => {
224- view . detectChanges ( ) ;
225+ rootTC . detectChanges ( ) ;
225226
226- var dispatchedEvent = clickOnElement ( view ) ;
227+ var dispatchedEvent = clickOnElement ( rootTC ) ;
227228 expect ( dispatchedEvent . defaultPrevented || ! dispatchedEvent . returnValue )
228229 . toBe ( true ) ;
229230
0 commit comments