@@ -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' ,
@@ -1156,6 +1159,7 @@ describe('state', function () {
1156
1159
1157
1160
describe ( "typed parameter handling" , function ( ) {
1158
1161
beforeEach ( function ( ) {
1162
+ var $state = $get ( '$state' )
1159
1163
stateProvider . state ( {
1160
1164
name : "types" ,
1161
1165
url : "/types/{p1:string}/{p2:date}" ,
@@ -1255,6 +1259,34 @@ describe('state', function () {
1255
1259
extend ( params , { p5 : true } ) ;
1256
1260
check ( 'types.substate' , "/types/foo/2014-11-15/sub/10/%7B%22baz%22:%22qux%22%7D?p5=1" , params , defaults , nonurl ) ;
1257
1261
} ) ) ;
1262
+
1263
+ it ( 'should support non-url parameters' , inject ( function ( $state , $q , $stateParams ) {
1264
+ $state . transitionTo ( A ) ; $q . flush ( ) ;
1265
+ expect ( $state . is ( A ) ) . toBe ( true ) ;
1266
+
1267
+ $state . go ( 'URLLESS' , { myparam : "0" } ) ; $q . flush ( ) ; // string "0" decodes to 0
1268
+ expect ( $state . current . name ) . toBe ( "URLLESS" ) ;
1269
+ expect ( $stateParams . myparam ) . toBe ( 0 ) ;
1270
+
1271
+ $state . go ( 'URLLESS' , { myparam : "1" } ) ; $q . flush ( ) ; // string "1" decodes to 1
1272
+ expect ( $stateParams . myparam ) . toBe ( 1 ) ;
1273
+ } ) ) ;
1274
+
1275
+ it ( 'should not transition if a required non-url parameter is missing' , inject ( function ( $state , $q , $stateParams ) {
1276
+ $state . transitionTo ( A ) ; $q . flush ( ) ;
1277
+ expect ( $state . current . name ) . toBe ( "A" ) ;
1278
+
1279
+ $state . go ( 'URLLESS' ) ; $q . flush ( ) ; // Missing required parameter; transition fails
1280
+ expect ( $state . current . name ) . toBe ( "A" ) ;
1281
+ } ) ) ;
1282
+
1283
+ it ( 'should not transition if a required non-url parameter is invalid' , inject ( function ( $state , $q , $stateParams ) {
1284
+ $state . transitionTo ( A ) ; $q . flush ( ) ;
1285
+ expect ( $state . current . name ) . toBe ( "A" ) ;
1286
+
1287
+ $state . go ( 'URLLESS' , { myparam : "somestring" } ) ; $q . flush ( ) ; // string "somestring" is not an int
1288
+ expect ( $state . current . name ) . toBe ( "A" ) ;
1289
+ } ) ) ;
1258
1290
} ) ;
1259
1291
1260
1292
it ( 'should revert to last known working url on state change failure' , inject ( function ( $state , $rootScope , $location , $q ) {
0 commit comments