forked from nodejs/undici
-
Notifications
You must be signed in to change notification settings - Fork 2
/
response.js
126 lines (106 loc) · 2.62 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
'use strict'
const { test } = require('tap')
const {
Response
} = require('../../')
test('arg validation', async (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'
})
}, RangeError)
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.toString()
}, TypeError)
t.throws(() => {
Response.prototype.url.toString()
}, TypeError)
t.throws(() => {
Response.prototype.redirected.toString()
}, TypeError)
t.throws(() => {
Response.prototype.status.toString()
}, TypeError)
t.throws(() => {
Response.prototype.ok.toString()
}, TypeError)
t.throws(() => {
Response.prototype.statusText.toString()
}, TypeError)
t.throws(() => {
Response.prototype.headers.toString()
}, TypeError)
t.throws(() => {
// eslint-disable-next-line no-unused-expressions
Response.prototype.body
}, TypeError)
t.throws(() => {
// eslint-disable-next-line no-unused-expressions
Response.prototype.bodyUsed
}, TypeError)
t.throws(() => {
Response.prototype.clone.call(null)
}, TypeError)
await t.rejects(async () => {
await new Response('http://localhost').text.call({
blob () {
return {
text () {
return Promise.resolve('emulating response.blob()')
}
}
}
})
}, 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()
})