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 @@ -353,17 +353,24 @@ LocationHashbangInHtml5Url.prototype =
353
353
* @return {string } search
354
354
*/
355
355
search : function ( search , paramValue ) {
356
- if ( isUndefined ( search ) )
357
- return this . $$search ;
358
-
359
- if ( isDefined ( paramValue ) ) {
360
- if ( paramValue === null ) {
361
- delete this . $$search [ search ] ;
362
- } else {
363
- this . $$search [ search ] = paramValue ;
364
- }
365
- } else {
366
- this . $$search = isString ( search ) ? parseKeyValue ( search ) : search ;
356
+ switch ( arguments . length ) {
357
+ case 0 :
358
+ return this . $$search ;
359
+ case 1 :
360
+ if ( isString ( search ) ) {
361
+ this . $$search = parseKeyValue ( search ) ;
362
+ } else if ( isObject ( search ) ) {
363
+ this . $$search = search ;
364
+ } else {
365
+ throw $locationMinErr ( 'wpt' , 'First parameter of function must be string or an object.' ) ;
366
+ }
367
+ break ;
368
+ default :
369
+ if ( paramValue == undefined || paramValue == null ) {
370
+ delete this . $$search [ search ] ;
371
+ } else {
372
+ this . $$search [ search ] = paramValue ;
373
+ }
367
374
}
368
375
369
376
this . $$compose ( ) ;
Original file line number Diff line number Diff line change @@ -66,6 +66,35 @@ describe('$location', function() {
66
66
} ) ;
67
67
68
68
69
+ it ( 'search() should handle multiple value' , function ( ) {
70
+ url . search ( 'a&b' ) ;
71
+ expect ( url . search ( ) ) . toEqual ( { a : true , b : true } ) ;
72
+
73
+ url . search ( 'a' , null ) ;
74
+
75
+ expect ( url . search ( ) ) . toEqual ( { b : true } ) ;
76
+
77
+ url . search ( 'b' , undefined ) ;
78
+ expect ( url . search ( ) ) . toEqual ( { } ) ;
79
+ } ) ;
80
+
81
+
82
+ it ( 'search() should handle single value' , function ( ) {
83
+ url . search ( 'ignore' ) ;
84
+ expect ( url . search ( ) ) . toEqual ( { ignore : true } ) ;
85
+ } ) ;
86
+
87
+
88
+ it ( 'search() should throw error an incorrect argument' , function ( ) {
89
+ expect ( function ( ) {
90
+ url . search ( null ) ;
91
+ } ) . toThrow ( '[$location:wpt] First parameter of function must be string or an object.' ) ;
92
+ expect ( function ( ) {
93
+ url . search ( undefined ) ;
94
+ } ) . toThrow ( '[$location:wpt] First parameter of function must be string or an object.' ) ;
95
+ } ) ;
96
+
97
+
69
98
it ( 'hash() should change hash fragment' , function ( ) {
70
99
url . hash ( 'new-hash' ) ;
71
100
expect ( url . hash ( ) ) . toBe ( 'new-hash' ) ;
You can’t perform that action at this time.
0 commit comments