forked from nodejs/undici
-
Notifications
You must be signed in to change notification settings - Fork 2
/
headers-iterator.js
46 lines (36 loc) · 1.41 KB
/
headers-iterator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
'use strict'
const { test } = require('tap')
const { Headers } = require('../..')
test('Implements "Headers Iterator" properly', (t) => {
t.test('all iterators implement Headers Iterator', (t) => {
const headers = new Headers([['a', 'b'], ['c', 'd']])
for (const iterable of ['keys', 'values', 'entries', Symbol.iterator]) {
const gen = headers[iterable]()
t.ok(gen.constructor === Object)
t.ok(gen.prototype === undefined)
// eslint-disable-next-line no-proto
t.equal(gen.__proto__[Symbol.toStringTag], 'Headers Iterator')
// https://github.com/node-fetch/node-fetch/issues/1119#issuecomment-100222049
t.notOk(gen instanceof function * () {}.constructor)
// eslint-disable-next-line no-proto
t.ok(gen.__proto__.next.__proto__ === Function.prototype)
}
t.end()
})
t.test('Headers Iterator symbols are properly set', (t) => {
const headers = new Headers([['a', 'b'], ['c', 'd']])
const gen = headers.entries()
t.equal(typeof gen[Symbol.toStringTag], 'string')
t.equal(typeof gen[Symbol.iterator], 'function')
t.end()
})
t.test('Headers Iterator does not inherit Generator prototype methods', (t) => {
const headers = new Headers([['a', 'b'], ['c', 'd']])
const gen = headers.entries()
t.equal(gen.return, undefined)
t.equal(gen.throw, undefined)
t.equal(typeof gen.next, 'function')
t.end()
})
t.end()
})