@@ -16,11 +16,10 @@ import {
1616} from 'angular2/testing_internal' ;
1717
1818import { provide , Component , View , Injector , Inject } from 'angular2/core' ;
19- import { CONST , NumberWrapper , isPresent , Json } from 'angular2/src/core/facade/lang' ;
2019import { Promise , PromiseWrapper } from 'angular2/src/core/facade/async' ;
2120
2221import { RootRouter } from 'angular2/src/router/router' ;
23- import { Router , RouterOutlet , RouterLink , RouteParams , ROUTE_DATA } from 'angular2/router' ;
22+ import { Router , RouterOutlet , RouterLink , RouteParams , RouteData } from 'angular2/router' ;
2423import {
2524 RouteConfig ,
2625 Route ,
@@ -200,13 +199,12 @@ export function main() {
200199 it ( 'should inject route data into component' , inject ( [ AsyncTestCompleter ] , ( async ) => {
201200 compile ( )
202201 . then ( ( _ ) => rtr . config ( [
203- new Route ( { path : '/route-data' , component : RouteDataCmp , data : { ' isAdmin' : true } } )
202+ new Route ( { path : '/route-data' , component : RouteDataCmp , data : { isAdmin : true } } )
204203 ] ) )
205204 . then ( ( _ ) => rtr . navigateByUrl ( '/route-data' ) )
206205 . then ( ( _ ) => {
207206 rootTC . detectChanges ( ) ;
208- expect ( rootTC . debugElement . nativeElement )
209- . toHaveText ( Json . stringify ( { 'isAdmin' : true } ) ) ;
207+ expect ( rootTC . debugElement . nativeElement ) . toHaveText ( 'true' ) ;
210208 async . done ( ) ;
211209 } ) ;
212210 } ) ) ;
@@ -221,48 +219,20 @@ export function main() {
221219 . then ( ( _ ) => rtr . navigateByUrl ( '/route-data' ) )
222220 . then ( ( _ ) => {
223221 rootTC . detectChanges ( ) ;
224- expect ( rootTC . debugElement . nativeElement )
225- . toHaveText ( Json . stringify ( { 'isAdmin' : true } ) ) ;
222+ expect ( rootTC . debugElement . nativeElement ) . toHaveText ( 'true' ) ;
226223 async . done ( ) ;
227224 } ) ;
228225 } ) ) ;
229226
230- it ( 'should inject null if the route has no data property' ,
227+ it ( 'should inject empty object if the route has no data property' ,
231228 inject ( [ AsyncTestCompleter ] , ( async ) => {
232229 compile ( )
233230 . then ( ( _ ) => rtr . config (
234231 [ new Route ( { path : '/route-data-default' , component : RouteDataCmp } ) ] ) )
235232 . then ( ( _ ) => rtr . navigateByUrl ( '/route-data-default' ) )
236233 . then ( ( _ ) => {
237234 rootTC . detectChanges ( ) ;
238- expect ( rootTC . debugElement . nativeElement ) . toHaveText ( 'null' ) ;
239- async . done ( ) ;
240- } ) ;
241- } ) ) ;
242-
243- it ( 'should allow an array as the route data' , inject ( [ AsyncTestCompleter ] , ( async ) => {
244- compile ( )
245- . then ( ( _ ) => rtr . config ( [
246- new Route ( { path : '/route-data-array' , component : RouteDataCmp , data : [ 1 , 2 , 3 ] } )
247- ] ) )
248- . then ( ( _ ) => rtr . navigateByUrl ( '/route-data-array' ) )
249- . then ( ( _ ) => {
250- rootTC . detectChanges ( ) ;
251- expect ( rootTC . debugElement . nativeElement ) . toHaveText ( Json . stringify ( [ 1 , 2 , 3 ] ) ) ;
252- async . done ( ) ;
253- } ) ;
254- } ) ) ;
255-
256- it ( 'should allow a string as the route data' , inject ( [ AsyncTestCompleter ] , ( async ) => {
257- compile ( )
258- . then ( ( _ ) => rtr . config ( [
259- new Route (
260- { path : '/route-data-string' , component : RouteDataCmp , data : 'hello world' } )
261- ] ) )
262- . then ( ( _ ) => rtr . navigateByUrl ( '/route-data-string' ) )
263- . then ( ( _ ) => {
264- rootTC . detectChanges ( ) ;
265- expect ( rootTC . debugElement . nativeElement ) . toHaveText ( Json . stringify ( 'hello world' ) ) ;
235+ expect ( rootTC . debugElement . nativeElement ) . toHaveText ( '' ) ;
266236 async . done ( ) ;
267237 } ) ;
268238 } ) ) ;
@@ -298,10 +268,8 @@ function AsyncRouteDataCmp() {
298268@Component ( { selector : 'data-cmp' } )
299269@View ( { template : "{{myData}}" } )
300270class RouteDataCmp {
301- myData : string ;
302- constructor ( @Inject ( ROUTE_DATA ) data : any ) {
303- this . myData = isPresent ( data ) ? Json . stringify ( data ) : 'null' ;
304- }
271+ myData : boolean ;
272+ constructor ( data : RouteData ) { this . myData = data . get ( 'isAdmin' ) ; }
305273}
306274
307275@Component ( { selector : 'user-cmp' } )
0 commit comments