1'use strict'; 2 3// Tests below are not from WPT. 4 5require('../common'); 6const assert = require('assert'); 7 8{ 9 const params = new URLSearchParams(); 10 assert.throws(() => { 11 params.delete.call(undefined); 12 }, { 13 code: 'ERR_INVALID_THIS', 14 name: 'TypeError', 15 message: 'Value of "this" must be of type URLSearchParams' 16 }); 17 assert.throws(() => { 18 params.delete(); 19 }, { 20 code: 'ERR_MISSING_ARGS', 21 name: 'TypeError', 22 message: 'The "name" argument must be specified' 23 }); 24 25 const obj = { 26 toString() { throw new Error('toString'); }, 27 valueOf() { throw new Error('valueOf'); } 28 }; 29 const sym = Symbol(); 30 assert.throws(() => params.delete(obj), /^Error: toString$/); 31 assert.throws(() => params.delete(sym), 32 /^TypeError: Cannot convert a Symbol value to a string$/); 33} 34 35// https://github.com/nodejs/node/issues/10480 36// Emptying searchParams should correctly update url's query 37{ 38 const url = new URL('http://domain?var=1&var=2&var=3'); 39 for (const param of url.searchParams.keys()) { 40 url.searchParams.delete(param); 41 } 42 assert.strictEqual(url.searchParams.toString(), ''); 43 assert.strictEqual(url.search, ''); 44 assert.strictEqual(url.href, 'http://domain/'); 45} 46