-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathheaders-to-object.node.test.ts
More file actions
54 lines (47 loc) · 1.78 KB
/
Copy pathheaders-to-object.node.test.ts
File metadata and controls
54 lines (47 loc) · 1.78 KB
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
// @vitest-environment node
import { headersToObject } from './headers-to-object'
import { Headers } from '../headers'
describe('given Headers with a single header', () => {
it('should return that single header in an Object', () => {
const headers = new Headers({ 'Content-Type': 'application/json' })
expect(headersToObject(headers)).toEqual({
'content-type': 'application/json',
})
})
})
describe('given Headers with a single header and multiple values', () => {
it('should put that header values into an array', () => {
const headers = new Headers({ Accept: 'application/json' })
headers.append('Accept', 'text/plain')
expect(headersToObject(headers)).toEqual({
accept: ['application/json', 'text/plain'],
})
})
})
describe('given Headers with multiple different headers', () => {
it('should return an object representing those headers', () => {
const headers = new Headers({
Accept: 'application/json',
'Content-Length': '1234',
'Content-Type': 'application/json',
})
headers.append('Accept', 'text/plain')
expect(headersToObject(headers)).toEqual({
accept: ['application/json', 'text/plain'],
'content-length': '1234',
'content-type': 'application/json',
})
})
})
describe('given Headers with a single header that includes a semicolon', () => {
it('should preserve a single header', () => {
const headers = new Headers({
'user-agent':
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.0 Safari/537.36',
})
expect(headersToObject(headers)).toEqual({
'user-agent':
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.0 Safari/537.36',
})
})
})