From c4726447f3bad1c71244fb99c98738ff0354a034 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Fri, 5 May 2023 18:59:16 +0200 Subject: [PATCH] URLSearchParams: add tests for two-argument delete() and has() For https://github.com/whatwg/url/pull/735. --- url/urlsearchparams-delete.any.js | 9 +++++++++ url/urlsearchparams-has.any.js | 13 +++++++++++++ 2 files changed, 22 insertions(+) diff --git a/url/urlsearchparams-delete.any.js b/url/urlsearchparams-delete.any.js index 28ebbce5f13bd8..f9c623b90b175d 100644 --- a/url/urlsearchparams-delete.any.js +++ b/url/urlsearchparams-delete.any.js @@ -61,3 +61,12 @@ test(() => { assert_equals(url.pathname, 'space '); assert_equals(url.href, 'data:space #test'); }, 'Changing the query of a URL with an opaque path can impact the path if the URL has no fragment'); + +test(() => { + const params = new URLSearchParams(); + params.append('a', 'b'); + params.append('a', 'c'); + params.append('a', 'd'); + params.delete('a', 'c'); + assert_equals(params.toString(), 'a=b&a=d'); +}, "Two-argument delete()"); diff --git a/url/urlsearchparams-has.any.js b/url/urlsearchparams-has.any.js index 673dce77dc44ab..54cbf286db4a3d 100644 --- a/url/urlsearchparams-has.any.js +++ b/url/urlsearchparams-has.any.js @@ -22,3 +22,16 @@ test(function() { params.delete('first'); assert_false(params.has('first'), 'Search params object has no name "first"'); }, 'has() following delete()'); + +test(() => { + const params = new URLSearchParams("a=b&a=d&c&e&"); + assert_true(params.has('a', 'b')); + assert_false(params.has('a', 'c')); + assert_true(params.has('a', 'd')); + assert_true(params.has('e', '')); + params.append('first', null); + assert_false(params.has('first', '')); + assert_true(params.has('first', 'null')); + params.delete('a', 'b'); + assert_true(params.has('a', 'd')); +}, "Two-argument has()");