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`
This commit is contained in:
Gal Schlezinger 2022-06-21 19:39:40 +03:00 committed by GitHub
parent ee7648ae0a
commit ff55e4a7f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,7 +2,7 @@
* @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) => ({
body: await response.json(),
@ -44,3 +44,12 @@ it('automatically parses and formats JSON', async () => {
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',
})
})