fix(UrlSearchParams): change a behavior when a param value is null or undefined (#11990)
This commit is contained in:

committed by
Chuck Jazdzewski

parent
3ee8c75eff
commit
9cc0a4ed10
@ -149,5 +149,23 @@ export function main() {
|
||||
expect(paramsC.toString()).toEqual('a=2&q=4%2B&c=8');
|
||||
});
|
||||
|
||||
it('should remove the parameter when set to undefined or null', () => {
|
||||
const params = new URLSearchParams('q=Q');
|
||||
params.set('q', undefined);
|
||||
expect(params.has('q')).toBe(false);
|
||||
expect(params.toString()).toEqual('');
|
||||
params.set('q', null);
|
||||
expect(params.has('q')).toBe(false);
|
||||
expect(params.toString()).toEqual('');
|
||||
});
|
||||
|
||||
it('should ignore the value when append undefined or null', () => {
|
||||
const params = new URLSearchParams('q=Q');
|
||||
params.append('q', undefined);
|
||||
expect(params.toString()).toEqual('q=Q');
|
||||
params.append('q', null);
|
||||
expect(params.toString()).toEqual('q=Q');
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user