cloudflare/cloudflare-typescript
Publicmirrored fromhttps://github.com/cloudflare/cloudflare-typescriptAvailable
tests/responses.test.ts
25lines · modecode
| 1 | import { createResponseHeaders } from 'cloudflare/core'; |
| 2 | import { Headers } from 'cloudflare/_shims/index'; |
| 3 | |
| 4 | describe('response parsing', () => { |
| 5 | // TODO: test unicode characters |
| 6 | test('headers are case agnostic', async () => { |
| 7 | const headers = createResponseHeaders(new Headers({ 'Content-Type': 'foo', Accept: 'text/plain' })); |
| 8 | expect(headers['content-type']).toEqual('foo'); |
| 9 | expect(headers['Content-type']).toEqual('foo'); |
| 10 | expect(headers['Content-Type']).toEqual('foo'); |
| 11 | expect(headers['accept']).toEqual('text/plain'); |
| 12 | expect(headers['Accept']).toEqual('text/plain'); |
| 13 | expect(headers['Hello-World']).toBeUndefined(); |
| 14 | }); |
| 15 | |
| 16 | test('duplicate headers are concatenated', () => { |
| 17 | const headers = createResponseHeaders( |
| 18 | new Headers([ |
| 19 | ['Content-Type', 'text/xml'], |
| 20 | ['Content-Type', 'application/json'], |
| 21 | ]), |
| 22 | ); |
| 23 | expect(headers['content-type']).toBe('text/xml, application/json'); |
| 24 | }); |
| 25 | }); |
| 26 | |