Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fcd08b8

Browse filesBrowse files
hiroppyevanlucas
authored andcommitted
test: add tests for searchParams
PR-URL: #10952 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
1 parent c329843 commit fcd08b8
Copy full SHA for fcd08b8
Expand file treeCollapse file tree

11 files changed

+151
-1
lines changed
Open diff view settings
Collapse file

‎test/parallel/test-whatwg-url-searchparams-append.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-whatwg-url-searchparams-append.js
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,10 @@ assert.strictEqual(params.get('third'), '',
4646
params.append('first', 10);
4747
assert.strictEqual(params.get('first'), '1',
4848
'Search params object has name "first" with value "1"');
49+
50+
assert.throws(() => {
51+
params.append.call(undefined);
52+
}, /^TypeError: Value of `this` is not a URLSearchParams$/);
53+
assert.throws(() => {
54+
params.set('a');
55+
}, /^TypeError: "name" and "value" arguments must be specified$/);
Collapse file

‎test/parallel/test-whatwg-url-searchparams-delete.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-whatwg-url-searchparams-delete.js
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ params.delete('first');
4141
assert.strictEqual(false, params.has('first'),
4242
'Search params object has no "first" name');
4343

44+
assert.throws(() => {
45+
params.delete.call(undefined);
46+
}, /^TypeError: Value of `this` is not a URLSearchParams$/);
47+
assert.throws(() => {
48+
params.delete();
49+
}, /^TypeError: "name" argument must be specified$/);
50+
4451
// https://github.com/nodejs/node/issues/10480
4552
// Emptying searchParams should correctly update url's query
4653
{
Collapse file
+33Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'use strict';
2+
3+
require('../common');
4+
const assert = require('assert');
5+
const URLSearchParams = require('url').URLSearchParams;
6+
7+
const params = new URLSearchParams('a=b&c=d');
8+
const entries = params.entries();
9+
assert.strictEqual(typeof entries[Symbol.iterator], 'function');
10+
assert.strictEqual(entries[Symbol.iterator](), entries);
11+
assert.deepStrictEqual(entries.next(), {
12+
value: ['a', 'b'],
13+
done: false
14+
});
15+
assert.deepStrictEqual(entries.next(), {
16+
value: ['c', 'd'],
17+
done: false
18+
});
19+
assert.deepStrictEqual(entries.next(), {
20+
value: undefined,
21+
done: true
22+
});
23+
assert.deepStrictEqual(entries.next(), {
24+
value: undefined,
25+
done: true
26+
});
27+
28+
assert.throws(() => {
29+
entries.next.call(undefined);
30+
}, /^TypeError: Value of `this` is not a URLSearchParamsIterator$/);
31+
assert.throws(() => {
32+
params.entries.call(undefined);
33+
}, /^TypeError: Value of `this` is not a URLSearchParams$/);
Collapse file

‎test/parallel/test-whatwg-url-searchparams-foreach.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-whatwg-url-searchparams-foreach.js
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ let a, b, i;
1212
const params = new URLSearchParams('a=1&b=2&c=3');
1313
const keys = [];
1414
const values = [];
15-
params.forEach(function(value, key) {
15+
params.forEach((value, key) => {
1616
keys.push(key);
1717
values.push(value);
1818
});
@@ -37,3 +37,7 @@ b = a.searchParams;
3737
for (i of b) {
3838
common.fail('should not be reached');
3939
}
40+
41+
assert.throws(() => {
42+
params.forEach.call(undefined);
43+
}, /^TypeError: Value of `this` is not a URLSearchParams$/);
Collapse file

‎test/parallel/test-whatwg-url-searchparams-get.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-whatwg-url-searchparams-get.js
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,10 @@ assert.strictEqual(params.get('third'), '',
2929
'Search params object has name "third" with empty value.');
3030
assert.strictEqual(params.get('fourth'), null,
3131
'Search params object has no "fourth" name and value.');
32+
33+
assert.throws(() => {
34+
params.get.call(undefined);
35+
}, /^TypeError: Value of `this` is not a URLSearchParams$/);
36+
assert.throws(() => {
37+
params.get();
38+
}, /^TypeError: "name" argument must be specified$/);
Collapse file

‎test/parallel/test-whatwg-url-searchparams-getall.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-whatwg-url-searchparams-getall.js
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,10 @@ assert(matches && matches.length == 1,
3636
'Search params object has values for name "a"');
3737
assert.deepStrictEqual(matches, ['one'],
3838
'Search params object has expected name "a" values');
39+
40+
assert.throws(() => {
41+
params.getAll.call(undefined);
42+
}, /^TypeError: Value of `this` is not a URLSearchParams$/);
43+
assert.throws(() => {
44+
params.getAll();
45+
}, /^TypeError: "name" argument must be specified$/);
Collapse file

‎test/parallel/test-whatwg-url-searchparams-has.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-whatwg-url-searchparams-has.js
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,10 @@ assert.strictEqual(false, params.has('d'),
3333
params.delete('first');
3434
assert.strictEqual(false, params.has('first'),
3535
'Search params object has no name "first"');
36+
37+
assert.throws(() => {
38+
params.has.call(undefined);
39+
}, /^TypeError: Value of `this` is not a URLSearchParams$/);
40+
assert.throws(() => {
41+
params.has();
42+
}, /^TypeError: "name" argument must be specified$/);
Collapse file
+34Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict';
2+
3+
require('../common');
4+
const assert = require('assert');
5+
const URLSearchParams = require('url').URLSearchParams;
6+
7+
const params = new URLSearchParams('a=b&c=d');
8+
const keys = params.keys();
9+
10+
assert.strictEqual(typeof keys[Symbol.iterator], 'function');
11+
assert.strictEqual(keys[Symbol.iterator](), keys);
12+
assert.deepStrictEqual(keys.next(), {
13+
value: 'a',
14+
done: false
15+
});
16+
assert.deepStrictEqual(keys.next(), {
17+
value: 'c',
18+
done: false
19+
});
20+
assert.deepStrictEqual(keys.next(), {
21+
value: undefined,
22+
done: true
23+
});
24+
assert.deepStrictEqual(keys.next(), {
25+
value: undefined,
26+
done: true
27+
});
28+
29+
assert.throws(() => {
30+
keys.next.call(undefined);
31+
}, /^TypeError: Value of `this` is not a URLSearchParamsIterator$/);
32+
assert.throws(() => {
33+
params.keys.call(undefined);
34+
}, /^TypeError: Value of `this` is not a URLSearchParams$/);
Collapse file

‎test/parallel/test-whatwg-url-searchparams-set.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-whatwg-url-searchparams-set.js
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,10 @@ assert.strictEqual(true, params.has('a'),
3232
'Search params object has name "a"');
3333
assert.strictEqual(params.get('a'), '4',
3434
'Search params object has name "a" with value "4"');
35+
36+
assert.throws(() => {
37+
params.set.call(undefined);
38+
}, /^TypeError: Value of `this` is not a URLSearchParams$/);
39+
assert.throws(() => {
40+
params.set('a');
41+
}, /^TypeError: "name" and "value" arguments must be specified$/);
Collapse file

‎test/parallel/test-whatwg-url-searchparams-stringifier.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-whatwg-url-searchparams-stringifier.js
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,6 @@ assert.strictEqual(params + '', 'a%F0%9F%92%A9b=c');
110110
// The lone '=' _does_ survive the roundtrip.
111111
params = new URLSearchParams('a=&a=b');
112112
assert.strictEqual(params.toString(), 'a=&a=b');
113+
assert.throws(() => {
114+
params.toString.call(undefined);
115+
}, /^TypeError: Value of `this` is not a URLSearchParams$/);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.