@@ -1349,6 +1349,8 @@ describe('state', function () {
13491349
13501350
13511351 describe ( "typed parameter handling" , function ( ) {
1352+ var checkStateUrl ;
1353+
13521354 beforeEach ( function ( ) {
13531355 $stateProvider . state ( {
13541356 name : "types" ,
@@ -1367,6 +1369,28 @@ describe('state', function () {
13671369 }
13681370 } ) ;
13691371 } ) ;
1372+
1373+ beforeEach ( inject ( function ( $state , $location , $q , $rootScope ) {
1374+ function _check_ ( state , url , params , defaults , nonurlparams ) {
1375+ $state . go ( state , extend ( { } , nonurlparams , params ) ) ;
1376+ $q . flush ( ) ;
1377+
1378+ expect ( $state . current . name ) . toBe ( state . name || state ) ; // allow object
1379+ expect ( obj ( $state . params ) ) . toEqualData ( extend ( { } , defaults , params , nonurlparams ) ) ;
1380+ expect ( $location . url ( ) ) . toBe ( url ) ;
1381+
1382+ initStateTo ( A ) ;
1383+
1384+ $location . url ( url ) ;
1385+ $rootScope . $broadcast ( "$locationChangeSuccess" ) ;
1386+ $q . flush ( ) ;
1387+
1388+ expect ( $state . current . name ) . toBe ( state . name || state ) ; // allow object
1389+ expect ( obj ( $state . params ) ) . toEqualData ( extend ( { } , defaults , params ) ) ;
1390+ expect ( $location . url ( ) ) . toBe ( url ) ;
1391+ }
1392+ checkStateUrl = _check_ ;
1393+ } ) ) ;
13701394
13711395 it ( 'should initialize parameters without a hacky empty test' , inject ( function ( $urlMatcherFactory , $state ) {
13721396 new UrlMatcher ( "" ) ;
@@ -1425,43 +1449,21 @@ describe('state', function () {
14251449 expect ( $state . params . nonurl && $state . params . nonurl . errorscope ) . toBe ( $rootScope ) ;
14261450 } ) ) ;
14271451
1428- function expectStateUrlMappingFn ( $state , $rootScope , $q , $location ) {
1429- return function ( state , url , params , defaults , nonurlparams ) {
1430- $state . go ( state , extend ( { } , nonurlparams , params ) ) ;
1431- $q . flush ( ) ;
1432-
1433- expect ( $state . current . name ) . toBe ( state . name || state ) ; // allow object
1434- expect ( obj ( $state . params ) ) . toEqualData ( extend ( { } , defaults , params , nonurlparams ) ) ;
1435- expect ( $location . url ( ) ) . toBe ( url ) ;
1436-
1437- initStateTo ( A ) ;
1438-
1439- $location . url ( url ) ;
1440- $rootScope . $broadcast ( "$locationChangeSuccess" ) ;
1441- $q . flush ( ) ;
1442-
1443- expect ( $state . current . name ) . toBe ( state . name || state ) ; // allow object
1444- expect ( obj ( $state . params ) ) . toEqualData ( extend ( { } , defaults , params ) ) ;
1445- expect ( $location . url ( ) ) . toBe ( url ) ;
1446- }
1447- }
1448-
14491452 it ( 'should map to/from the $location.url() and $stateParams' , inject ( function ( $state , $location , $q , $rootScope ) {
14501453 var nov15 = new Date ( 2014 , 10 , 15 ) ;
14511454 var defaults = { p1 : [ 'defaultValue' ] , p2 : nov15 , nonurl : null } ;
14521455 var params = { p1 : [ "foo" ] , p2 : nov15 } ;
14531456 var nonurl = { nonurl : { foo : 'bar' } } ;
14541457
1455- var check = expectStateUrlMappingFn ( $state , $rootScope , $q , $location ) ;
1456- check ( 'types' , '/types/defaultValue/2014-11-15' , { } , defaults ) ;
1457- check ( 'types' , "/types/foo/2014-11-15" , params , defaults , nonurl ) ;
1458+ checkStateUrl ( 'types' , '/types/defaultValue/2014-11-15' , { } , defaults ) ;
1459+ checkStateUrl ( 'types' , "/types/foo/2014-11-15" , params , defaults , nonurl ) ;
14581460
14591461 extend ( defaults , { "p3[]" : [ 10 ] } ) ;
14601462 extend ( params , { p4 : { baz : "qux" } } ) ;
1461- check ( 'types.substate' , "/types/foo/2014-11-15/sub/10/%7B%22baz%22:%22qux%22%7D" , params , defaults , nonurl ) ;
1463+ checkStateUrl ( 'types.substate' , "/types/foo/2014-11-15/sub/10/%7B%22baz%22:%22qux%22%7D" , params , defaults , nonurl ) ;
14621464
14631465 extend ( params , { p5 : true } ) ;
1464- check ( 'types.substate' , "/types/foo/2014-11-15/sub/10/%7B%22baz%22:%22qux%22%7D?p5=1" , params , defaults , nonurl ) ;
1466+ checkStateUrl ( 'types.substate' , "/types/foo/2014-11-15/sub/10/%7B%22baz%22:%22qux%22%7D?p5=1" , params , defaults , nonurl ) ;
14651467 } ) ) ;
14661468
14671469 it ( 'should support non-url parameters' , inject ( function ( $state , $q , $stateParams ) {
0 commit comments