-
Notifications
You must be signed in to change notification settings - Fork 502
/
response.js
104 lines (87 loc) · 2.12 KB
/
response.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
'use strict'
const { test } = require('tap')
const {
Response
} = require('../../')
test('arg validation', (t) => {
// constructor
t.throws(() => {
// eslint-disable-next-line
new Response(null, 0)
}, TypeError)
t.throws(() => {
// eslint-disable-next-line
new Response(null, {
status: 99
})
}, RangeError)
t.throws(() => {
// eslint-disable-next-line
new Response(null, {
status: 600
})
}, RangeError)
t.throws(() => {
// eslint-disable-next-line
new Response(null, {
status: '600'
})
}, TypeError)
t.throws(() => {
// eslint-disable-next-line
new Response(null, {
statusText: '\u0000'
})
}, TypeError)
for (const nullStatus of [204, 205, 304]) {
t.throws(() => {
// eslint-disable-next-line
new Response(new ArrayBuffer(16), {
status: nullStatus
})
}, TypeError)
}
t.doesNotThrow(() => {
Response.prototype[Symbol.toStringTag].charAt(0)
}, TypeError)
t.throws(() => {
Response.prototype.type.call(null)
}, TypeError)
t.throws(() => {
Response.prototype.url.call(null)
}, TypeError)
t.throws(() => {
Response.prototype.redirected.call(null)
}, TypeError)
t.throws(() => {
Response.prototype.status.call(null)
}, TypeError)
t.throws(() => {
Response.prototype.ok.call(null)
}, TypeError)
t.throws(() => {
Response.prototype.statusText.call(null)
}, TypeError)
t.throws(() => {
Response.prototype.headers.call(null)
}, TypeError)
t.throws(() => {
Response.prototype.clone.call(null)
}, TypeError)
t.end()
})
test('response clone', (t) => {
// https://github.com/nodejs/undici/issues/1122
const response1 = new Response(null, { status: 201 })
const response2 = new Response(undefined, { status: 201 })
t.equal(response1.body, response1.clone().body)
t.equal(response2.body, response2.clone().body)
t.equal(response2.body, null)
t.end()
})
test('Symbol.toStringTag', (t) => {
const resp = new Response()
t.equal(resp[Symbol.toStringTag], 'Response')
t.equal(Response.prototype[Symbol.toStringTag], 'Response')
t.end()
})