@@ -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' ,
@@ -1156,6 +1159,7 @@ describe('state', function () {
11561159
11571160 describe ( "typed parameter handling" , function ( ) {
11581161 beforeEach ( function ( ) {
1162+ var $state = $get ( '$state' )
11591163 stateProvider . state ( {
11601164 name : "types" ,
11611165 url : "/types/{p1:string}/{p2:date}" ,
@@ -1255,6 +1259,34 @@ describe('state', function () {
12551259 extend ( params , { p5 : true } ) ;
12561260 check ( 'types.substate' , "/types/foo/2014-11-15/sub/10/%7B%22baz%22:%22qux%22%7D?p5=1" , params , defaults , nonurl ) ;
12571261 } ) ) ;
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+ } ) ) ;
12581290 } ) ;
12591291
12601292 it ( 'should revert to last known working url on state change failure' , inject ( function ( $state , $rootScope , $location , $q ) {
0 commit comments