@@ -250,6 +250,7 @@ describe('state', function () {
250
250
} ,
251
251
OPT = { url : '/opt/:param' , params : { param : "100" } , template : "opt" } ,
252
252
OPT2 = { url : '/opt2/:param2/:param3' , params : { param3 : "300" , param4 : "400" } , template : "opt2" } ,
253
+ URLLESS = { url : '/urllessparams' , params : { myparam : { type : 'int' } } } ,
253
254
AppInjectable = { } ;
254
255
255
256
beforeEach ( module ( function ( $stateProvider , $provide ) {
@@ -274,6 +275,7 @@ describe('state', function () {
274
275
. state ( 'dynamicstate' , dynamicstate )
275
276
. state ( 'OPT' , OPT )
276
277
. state ( 'OPT.OPT2' , OPT2 )
278
+ . state ( 'URLLESS' , URLLESS )
277
279
. state ( 'home' , { url : "/" } )
278
280
. state ( 'home.item' , { url : "front/:id" } )
279
281
. state ( 'about' , {
@@ -1110,7 +1112,7 @@ describe('state', function () {
1110
1112
1111
1113
it ( "should return all of the state's config" , inject ( function ( $state ) {
1112
1114
var list = $state . get ( ) . sort ( function ( a , b ) { return ( a . name > b . name ) - ( b . name > a . name ) ; } ) ;
1113
- var names = [ '' , 'A' , 'B' , 'C' , 'D' , 'DD' , 'E' , 'F' , 'H' , 'HH' , 'HHH' , 'OPT' , 'OPT.OPT2' , 'RS' ,
1115
+ var names = [ '' , 'A' , 'B' , 'C' , 'D' , 'DD' , 'E' , 'F' , 'H' , 'HH' , 'HHH' , 'OPT' , 'OPT.OPT2' , 'RS' , 'URLLESS' ,
1114
1116
'about' , 'about.person' , 'about.person.item' , 'about.sidebar' , 'about.sidebar.item' ,
1115
1117
'badParam' , 'badParam2' , 'dynamicTemplate' , 'dynamicstate' , 'first' , 'home' , 'home.item' , 'home.redirect' ,
1116
1118
'json' , 'logA' , 'logA.logB' , 'logA.logB.logC' , 'resolveFail' , 'resolveTimeout' ,
@@ -1357,6 +1359,34 @@ describe('state', function () {
1357
1359
extend ( params , { p5 : true } ) ;
1358
1360
check ( 'types.substate' , "/types/foo/2014-11-15/sub/10/%7B%22baz%22:%22qux%22%7D?p5=1" , params , defaults , nonurl ) ;
1359
1361
} ) ) ;
1362
+
1363
+ it ( 'should support non-url parameters' , inject ( function ( $state , $q , $stateParams ) {
1364
+ $state . transitionTo ( A ) ; $q . flush ( ) ;
1365
+ expect ( $state . is ( A ) ) . toBe ( true ) ;
1366
+
1367
+ $state . go ( 'URLLESS' , { myparam : "0" } ) ; $q . flush ( ) ; // string "0" decodes to 0
1368
+ expect ( $state . current . name ) . toBe ( "URLLESS" ) ;
1369
+ expect ( $stateParams . myparam ) . toBe ( 0 ) ;
1370
+
1371
+ $state . go ( 'URLLESS' , { myparam : "1" } ) ; $q . flush ( ) ; // string "1" decodes to 1
1372
+ expect ( $stateParams . myparam ) . toBe ( 1 ) ;
1373
+ } ) ) ;
1374
+
1375
+ it ( 'should not transition if a required non-url parameter is missing' , inject ( function ( $state , $q , $stateParams ) {
1376
+ $state . transitionTo ( A ) ; $q . flush ( ) ;
1377
+ expect ( $state . current . name ) . toBe ( "A" ) ;
1378
+
1379
+ $state . go ( 'URLLESS' ) ; $q . flush ( ) ; // Missing required parameter; transition fails
1380
+ expect ( $state . current . name ) . toBe ( "A" ) ;
1381
+ } ) ) ;
1382
+
1383
+ it ( 'should not transition if a required non-url parameter is invalid' , inject ( function ( $state , $q , $stateParams ) {
1384
+ $state . transitionTo ( A ) ; $q . flush ( ) ;
1385
+ expect ( $state . current . name ) . toBe ( "A" ) ;
1386
+
1387
+ $state . go ( 'URLLESS' , { myparam : "somestring" } ) ; $q . flush ( ) ; // string "somestring" is not an int
1388
+ expect ( $state . current . name ) . toBe ( "A" ) ;
1389
+ } ) ) ;
1360
1390
} ) ;
1361
1391
1362
1392
it ( 'should revert to last known working url on state change failure' , inject ( function ( $state , $rootScope , $location , $q ) {
0 commit comments