value: new Proxy(tracked.searchParams, {
get(obj, key) {
if (key === 'get' || key === 'getAll' || key === 'has') {
- return (/**@type {string}*/ param) => {
+ return (/** @type {string} */ param, /** @type {string[]} */ ...rest) => {
search_params_callback(param);
- return obj[key](param);
+ return obj[key](param, ...rest);
};
}
url.searchParams.entries();
assert.ok(tracked);
});
+
+ test('tracks search params when using has(name, value) overload', () => {
+ let tracked = false;
+ const tracked_search_params = new Set();
+ const url = make_trackable(
+ new URL('https://svelte.dev/docs/kit?foo=1&foo=2'),
+ () => {
+ tracked = true;
+ },
+ (search_param) => {
+ tracked_search_params.add(search_param);
+ }
+ );
+
+ // has(name, value) should track the param and return correct result
+ assert.equal(url.searchParams.has('foo', '1'), true);
+ assert.ok(!tracked);
+ assert.ok(tracked_search_params.has('foo'));
+
+ // value argument should be forwarded correctly (not just checking name existence)
+ assert.equal(url.searchParams.has('foo', '3'), false);
+ assert.ok(!tracked);
+ });
});
describe('disable_search', (test) => {