@@ -32,6 +32,7 @@ describe('state', function () {
32
32
RSP = { url : '^/:doReload/search?term' , reloadOnSearch : false } ,
33
33
OPT = { url : '/opt/:param' , params : { param : "100" } } ,
34
34
OPT2 = { url : '/opt2/:param2/:param3' , params : { param3 : "300" , param4 : "400" } } ,
35
+ URLLESS = { url : '/urllessparams' , params : { myparam : { type : 'int' } } } ,
35
36
ISS2101 = { params : { bar : { squash : false , value : 'qux' } } , url : '/2101/{bar:string}' } ;
36
37
AppInjectable = { } ;
37
38
@@ -56,6 +57,7 @@ describe('state', function () {
56
57
. state ( 'HHH' , HHH )
57
58
. state ( 'OPT' , OPT )
58
59
. state ( 'OPT.OPT2' , OPT2 )
60
+ . state ( 'URLLESS' , URLLESS )
59
61
. state ( 'ISS2101' , ISS2101 )
60
62
. state ( 'RS' , RS )
61
63
. state ( 'RSP' , RSP )
@@ -989,6 +991,7 @@ describe('state', function () {
989
991
'OPT.OPT2' ,
990
992
'RS' ,
991
993
'RSP' ,
994
+ 'URLLESS' ,
992
995
'about' ,
993
996
'about.person' ,
994
997
'about.person.item' ,
@@ -1255,6 +1258,34 @@ describe('state', function () {
1255
1258
extend ( params , { p5 : true } ) ;
1256
1259
check ( 'types.substate' , "/types/foo/2014-11-15/sub/10/%7B%22baz%22:%22qux%22%7D?p5=1" , params , defaults , nonurl ) ;
1257
1260
} ) ) ;
1261
+
1262
+ it ( 'should support non-url parameters' , inject ( function ( $state , $q , $stateParams ) {
1263
+ $state . transitionTo ( A ) ; $q . flush ( ) ;
1264
+ expect ( $state . is ( A ) ) . toBe ( true ) ;
1265
+
1266
+ $state . go ( 'URLLESS' , { myparam : "0" } ) ; $q . flush ( ) ; // string "0" decodes to 0
1267
+ expect ( $state . current . name ) . toBe ( "URLLESS" ) ;
1268
+ expect ( $stateParams . myparam ) . toBe ( 0 ) ;
1269
+
1270
+ $state . go ( 'URLLESS' , { myparam : "1" } ) ; $q . flush ( ) ; // string "1" decodes to 1
1271
+ expect ( $stateParams . myparam ) . toBe ( 1 ) ;
1272
+ } ) ) ;
1273
+
1274
+ it ( 'should not transition if a required non-url parameter is missing' , inject ( function ( $state , $q , $stateParams ) {
1275
+ $state . transitionTo ( A ) ; $q . flush ( ) ;
1276
+ expect ( $state . current . name ) . toBe ( "A" ) ;
1277
+
1278
+ $state . go ( 'URLLESS' ) ; $q . flush ( ) ; // Missing required parameter; transition fails
1279
+ expect ( $state . current . name ) . toBe ( "A" ) ;
1280
+ } ) ) ;
1281
+
1282
+ it ( 'should not transition if a required non-url parameter is invalid' , inject ( function ( $state , $q , $stateParams ) {
1283
+ $state . transitionTo ( A ) ; $q . flush ( ) ;
1284
+ expect ( $state . current . name ) . toBe ( "A" ) ;
1285
+
1286
+ $state . go ( 'URLLESS' , { myparam : "somestring" } ) ; $q . flush ( ) ; // string "somestring" is not an int
1287
+ expect ( $state . current . name ) . toBe ( "A" ) ;
1288
+ } ) ) ;
1258
1289
} ) ;
1259
1290
1260
1291
it ( 'should revert to last known working url on state change failure' , inject ( function ( $state , $rootScope , $location , $q ) {
0 commit comments