-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
url: add custom inspection for URLSearchParams and its iterators
- Loading branch information
Showing
2 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
const assert = require('assert'); | ||
const util = require('util'); | ||
const URL = require('url').URL; | ||
|
||
// Until we export URLSearchParams | ||
const m = new URL('http://example.org'); | ||
const URLSearchParams = m.searchParams.constructor; | ||
|
||
const sp = new URLSearchParams('?a=a&b=b&b=c'); | ||
assert.strictEqual(util.inspect(sp), | ||
"URLSearchParams { 'a' => 'a', 'b' => 'b', 'b' => 'c' }"); | ||
assert.strictEqual(util.inspect(sp.keys()), | ||
"URLSearchParamsIterator { 'a', 'b', 'b' }"); | ||
assert.strictEqual(util.inspect(sp.values()), | ||
"URLSearchParamsIterator { 'a', 'b', 'c' }"); | ||
|
||
const iterator = sp.entries(); | ||
assert.strictEqual(util.inspect(iterator), | ||
"URLSearchParamsIterator { [ 'a', 'a' ], [ 'b', 'b' ], " + | ||
"[ 'b', 'c' ] }"); | ||
iterator.next(); | ||
assert.strictEqual(util.inspect(iterator), | ||
"URLSearchParamsIterator { [ 'b', 'b' ], [ 'b', 'c' ] }"); | ||
iterator.next(); | ||
iterator.next(); | ||
assert.strictEqual(util.inspect(iterator), | ||
'URLSearchParamsIterator { }'); |