@@ -32,6 +32,7 @@ describe('state', function () {
3232 RSP = { url : '^/:doReload/search?term' , reloadOnSearch : false } ,
3333 OPT = { url : '/opt/:param' , params : { param : "100" } } ,
3434 OPT2 = { url : '/opt2/:param2/:param3' , params : { param3 : "300" , param4 : "400" } } ,
35+ URLLESS = { url : '/urllessparams' , params : { myparam : { type : 'int' } } } ,
3536 ISS2101 = { params : { bar : { squash : false , value : 'qux' } } , url : '/2101/{bar:string}' } ;
3637 AppInjectable = { } ;
3738
@@ -56,6 +57,7 @@ describe('state', function () {
5657 . state ( 'HHH' , HHH )
5758 . state ( 'OPT' , OPT )
5859 . state ( 'OPT.OPT2' , OPT2 )
60+ . state ( 'URLLESS' , URLLESS )
5961 . state ( 'ISS2101' , ISS2101 )
6062 . state ( 'RS' , RS )
6163 . state ( 'RSP' , RSP )
@@ -989,6 +991,7 @@ describe('state', function () {
989991 'OPT.OPT2' ,
990992 'RS' ,
991993 'RSP' ,
994+ 'URLLESS' ,
992995 'about' ,
993996 'about.person' ,
994997 'about.person.item' ,
@@ -1255,6 +1258,34 @@ describe('state', function () {
12551258 extend ( params , { p5 : true } ) ;
12561259 check ( 'types.substate' , "/types/foo/2014-11-15/sub/10/%7B%22baz%22:%22qux%22%7D?p5=1" , params , defaults , nonurl ) ;
12571260 } ) ) ;
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+ } ) ) ;
12581289 } ) ;
12591290
12601291 it ( 'should revert to last known working url on state change failure' , inject ( function ( $state , $rootScope , $location , $q ) {
0 commit comments