-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(utils): accept HeadersInit, null, undefined in buildOutgoingHttpH…
…eaders (#212)
- Loading branch information
Showing
2 changed files
with
78 additions
and
8 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,73 @@ | ||
import { buildOutgoingHttpHeaders } from '../src/utils' | ||
|
||
describe('buildOutgoingHttpHeaders', () => { | ||
it('original content-type is preserved', () => { | ||
const headers = new Headers({ | ||
a: 'b', | ||
'content-type': 'text/html; charset=UTF-8', | ||
}) | ||
const result = buildOutgoingHttpHeaders(headers) | ||
expect(result).toEqual({ | ||
a: 'b', | ||
'content-type': 'text/html; charset=UTF-8', | ||
}) | ||
}) | ||
|
||
it('multiple set-cookie', () => { | ||
const headers = new Headers() | ||
headers.append('set-cookie', 'a') | ||
headers.append('set-cookie', 'b') | ||
const result = buildOutgoingHttpHeaders(headers) | ||
expect(result).toEqual({ | ||
'set-cookie': ['a', 'b'], | ||
'content-type': 'text/plain; charset=UTF-8', | ||
}) | ||
}) | ||
|
||
it('Headers', () => { | ||
const headers = new Headers({ | ||
a: 'b', | ||
}) | ||
const result = buildOutgoingHttpHeaders(headers) | ||
expect(result).toEqual({ | ||
a: 'b', | ||
'content-type': 'text/plain; charset=UTF-8', | ||
}) | ||
}) | ||
|
||
it('Record<string, string>', () => { | ||
const headers = { | ||
a: 'b', | ||
'Set-Cookie': 'c', // case-insensitive | ||
} | ||
const result = buildOutgoingHttpHeaders(headers) | ||
expect(result).toEqual({ | ||
a: 'b', | ||
'set-cookie': ['c'], | ||
'content-type': 'text/plain; charset=UTF-8', | ||
}) | ||
}) | ||
|
||
it('Record<string, string>[]', () => { | ||
const headers: HeadersInit = [['a', 'b']] | ||
const result = buildOutgoingHttpHeaders(headers) | ||
expect(result).toEqual({ | ||
a: 'b', | ||
'content-type': 'text/plain; charset=UTF-8', | ||
}) | ||
}) | ||
|
||
it('null', () => { | ||
const result = buildOutgoingHttpHeaders(null) | ||
expect(result).toEqual({ | ||
'content-type': 'text/plain; charset=UTF-8', | ||
}) | ||
}) | ||
|
||
it('undefined', () => { | ||
const result = buildOutgoingHttpHeaders(undefined) | ||
expect(result).toEqual({ | ||
'content-type': 'text/plain; charset=UTF-8', | ||
}) | ||
}) | ||
}) |