mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-08 04:22:09 +00:00
### 🔖 What's in there? Because Typescript's `libdom` does not have [`static Response.json()`](https://github.com/microsoft/TypeScript-DOM-lib-generator/issues/1444) (which modern browsers and edge runtimes are supporting), Typescript users can't use easily use it. This helper fills the gap. ### 🧪 How to test? It's covered with unit tests
35 lines
1.0 KiB
TypeScript
Vendored
35 lines
1.0 KiB
TypeScript
Vendored
/**
|
|
* @jest-environment @edge-runtime/jest-environment
|
|
*/
|
|
|
|
import { json } from '../src/response';
|
|
|
|
describe('json', () => {
|
|
it('returns a response with JSON content', async () => {
|
|
const content = { foo: 'bar' };
|
|
const response = json(content);
|
|
expect(response.headers.get('content-type')).toEqual('application/json');
|
|
expect(await response.json()).toEqual(content);
|
|
});
|
|
|
|
it('can set response init', async () => {
|
|
const content = { bar: 'baz' };
|
|
const status = 201;
|
|
const statusText = 'it is in';
|
|
const customHeader = 'x-custom';
|
|
const customHeaderValue = '1';
|
|
const response = json(content, {
|
|
status,
|
|
statusText,
|
|
headers: { [customHeader]: customHeaderValue },
|
|
});
|
|
expect(response).toMatchObject({
|
|
status,
|
|
statusText,
|
|
});
|
|
expect(response.headers.get('content-type')).toEqual('application/json');
|
|
expect(response.headers.get(customHeader)).toEqual(customHeaderValue);
|
|
expect(await response.json()).toEqual(content);
|
|
});
|
|
});
|