This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 3 files changed +51
-11
lines changed
docs/content/error/location
3 files changed +51
-11
lines changed Original file line number Diff line number Diff line change
1
+ @ngdoc error
2
+ @name $location:wpt
3
+ @fullName Wrong parameter type
4
+ @description
Original file line number Diff line number Diff line change @@ -349,17 +349,24 @@ LocationUrl.prototype = {
349
349
* @return {string } search
350
350
*/
351
351
search : function ( search , paramValue ) {
352
- if ( isUndefined ( search ) )
353
- return this . $$search ;
354
-
355
- if ( isDefined ( paramValue ) ) {
356
- if ( paramValue === null ) {
357
- delete this . $$search [ search ] ;
358
- } else {
359
- this . $$search [ search ] = paramValue ;
360
- }
361
- } else {
362
- this . $$search = isString ( search ) ? parseKeyValue ( search ) : search ;
352
+ switch ( arguments . length ) {
353
+ case 0 :
354
+ return this . $$search ;
355
+ case 1 :
356
+ if ( isString ( search ) ) {
357
+ this . $$search = parseKeyValue ( search ) ;
358
+ } else if ( isObject ( search ) ) {
359
+ this . $$search = search ;
360
+ } else {
361
+ throw $locationMinErr ( 'wpt' , 'First parameter of function must be string or an object.' ) ;
362
+ }
363
+ break ;
364
+ default :
365
+ if ( paramValue == undefined || paramValue == null ) {
366
+ delete this . $$search [ search ] ;
367
+ } else {
368
+ this . $$search [ search ] = paramValue ;
369
+ }
363
370
}
364
371
365
372
this . $$compose ( ) ;
Original file line number Diff line number Diff line change @@ -78,6 +78,35 @@ describe('$location', function() {
78
78
} ) ;
79
79
80
80
81
+ it ( 'search() should handle multiple value' , function ( ) {
82
+ url . search ( 'a&b' ) ;
83
+ expect ( url . search ( ) ) . toEqual ( { a : true , b : true } ) ;
84
+
85
+ url . search ( 'a' , null ) ;
86
+
87
+ expect ( url . search ( ) ) . toEqual ( { b : true } ) ;
88
+
89
+ url . search ( 'b' , undefined ) ;
90
+ expect ( url . search ( ) ) . toEqual ( { } ) ;
91
+ } ) ;
92
+
93
+
94
+ it ( 'search() should handle single value' , function ( ) {
95
+ url . search ( 'ignore' ) ;
96
+ expect ( url . search ( ) ) . toEqual ( { ignore : true } ) ;
97
+ } ) ;
98
+
99
+
100
+ it ( 'search() should throw error an incorrect argument' , function ( ) {
101
+ expect ( function ( ) {
102
+ url . search ( null ) ;
103
+ } ) . toThrow ( '[$location:wpt] First parameter of function must be string or an object.' ) ;
104
+ expect ( function ( ) {
105
+ url . search ( undefined ) ;
106
+ } ) . toThrow ( '[$location:wpt] First parameter of function must be string or an object.' ) ;
107
+ } ) ;
108
+
109
+
81
110
it ( 'hash() should change hash fragment' , function ( ) {
82
111
url . hash ( 'new-hash' ) ;
83
112
expect ( url . hash ( ) ) . toBe ( 'new-hash' ) ;
You can’t perform that action at this time.
0 commit comments