-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
187 additions
and
110 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 was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,57 +1,68 @@ | ||
import { guard, polyfilledOrNative } from './test-if' | ||
describe('headers', () => { | ||
it.each([ | ||
['host', 'vercel.com'], | ||
['content-length', '1234'], | ||
['content-type', 'application/json'], | ||
['transfer-encoding', 'chunked'], | ||
['connection', 'keep-alive'], | ||
['keep-alive', 'timeout=5'], | ||
['upgrade', 'websocket'], | ||
['expect', '100-continue'], | ||
])("sets '%s' header in the constructor", async (name, value) => { | ||
const headers = new Headers({ [name]: value }) | ||
expect(headers.get(name)).toBe(value) | ||
}) | ||
|
||
guard(it, polyfilledOrNative)( | ||
'sets header calling Headers constructor', | ||
async () => { | ||
it('sets header calling Headers constructor', async () => { | ||
const headers = new Headers() | ||
headers.set('cookie', 'hello=world') | ||
expect(headers.get('cookie')).toBe('hello=world') | ||
}, | ||
) | ||
|
||
guard(it, polyfilledOrNative)('multiple headers', async () => { | ||
const headers = new Headers() | ||
headers.append('set-cookie', 'foo=chocochip') | ||
headers.append('set-cookie', 'bar=chocochip') | ||
expect(headers.get('set-cookie')).toBe('foo=chocochip, bar=chocochip') | ||
expect([...headers]).toEqual([ | ||
['set-cookie', 'foo=chocochip'], | ||
['set-cookie', 'bar=chocochip'], | ||
]) | ||
}) | ||
}) | ||
|
||
guard(describe, polyfilledOrNative)('iterators', () => { | ||
const generate = () => { | ||
it('multiple headers', async () => { | ||
const headers = new Headers() | ||
headers.append('a', '1') | ||
headers.append('b', '2') | ||
headers.append('set-cookie', 'c=3') | ||
headers.append('set-cookie', 'd=4') | ||
return headers | ||
} | ||
|
||
test('#Symbol.iterator', () => { | ||
const entries = [...generate()] | ||
expect(entries).toEqual([ | ||
['a', '1'], | ||
['b', '2'], | ||
['set-cookie', 'c=3'], | ||
['set-cookie', 'd=4'], | ||
headers.append('set-cookie', 'foo=chocochip') | ||
headers.append('set-cookie', 'bar=chocochip') | ||
expect(headers.get('set-cookie')).toBe('foo=chocochip, bar=chocochip') | ||
expect([...headers]).toEqual([ | ||
['set-cookie', 'foo=chocochip'], | ||
['set-cookie', 'bar=chocochip'], | ||
]) | ||
}) | ||
|
||
test('#entries', () => { | ||
const entries = [...generate().entries()] | ||
expect(entries).toEqual([ | ||
['a', '1'], | ||
['b', '2'], | ||
['set-cookie', 'c=3'], | ||
['set-cookie', 'd=4'], | ||
]) | ||
}) | ||
describe('iterators', () => { | ||
const generate = () => { | ||
const headers = new Headers() | ||
headers.append('a', '1') | ||
headers.append('b', '2') | ||
headers.append('set-cookie', 'c=3') | ||
headers.append('set-cookie', 'd=4') | ||
return headers | ||
} | ||
|
||
test('#Symbol.iterator', () => { | ||
const entries = [...generate()] | ||
expect(entries).toEqual([ | ||
['a', '1'], | ||
['b', '2'], | ||
['set-cookie', 'c=3'], | ||
['set-cookie', 'd=4'], | ||
]) | ||
}) | ||
|
||
test('#entries', () => { | ||
const entries = [...generate().entries()] | ||
expect(entries).toEqual([ | ||
['a', '1'], | ||
['b', '2'], | ||
['set-cookie', 'c=3'], | ||
['set-cookie', 'd=4'], | ||
]) | ||
}) | ||
|
||
test('#values', () => { | ||
const values = [...generate().values()] | ||
expect(values).toEqual(['1', '2', 'c=3', 'd=4']) | ||
test('#values', () => { | ||
const values = [...generate().values()] | ||
expect(values).toEqual(['1', '2', 'c=3', 'd=4']) | ||
}) | ||
}) | ||
}) |
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
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