Unverified Commit ff55e4a7 authored by Gal Schlezinger's avatar Gal Schlezinger Committed by GitHub

add a test that verifies that NextResponse can be cloned (#37883)

This resolves #35573

I can't seem to reproduce the issue so I only created a unit test that verifies that it has the correct behavior.
@tavvy can you also check this PR out to see if it makes sense or not?

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
parent ee7648ae
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @jest-environment @edge-runtime/jest-environment * @jest-environment @edge-runtime/jest-environment
*/ */
import { NextResponse } from 'next/dist/server/web/spec-extension/response' import { NextResponse } from 'next/server/web/spec-extension/response'
const toJSON = async (response) => ({ const toJSON = async (response) => ({
body: await response.json(), body: await response.json(),
...@@ -44,3 +44,12 @@ it('automatically parses and formats JSON', async () => { ...@@ -44,3 +44,12 @@ it('automatically parses and formats JSON', async () => {
body: '', body: '',
}) })
}) })
it('can be cloned', async () => {
const fetchResponse = await fetch('https://example.vercel.sh')
const newResponse = new NextResponse(fetchResponse.body, fetchResponse)
expect(await newResponse.text()).toContain('Example Domain')
expect(Object.fromEntries(newResponse.headers)).toMatchObject({
server: 'Vercel',
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment