Skip to content

Commit

Permalink
Revert "remove old tests"
Browse files Browse the repository at this point in the history
This reverts commit 258e447.
  • Loading branch information
ijjk committed Jun 21, 2022
1 parent 258e447 commit ca97e7f
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test/unit/web-runtime/next-response.test.ts
Expand Up @@ -4,6 +4,47 @@

import { NextResponse } from 'next/server/web/spec-extension/response'

const toJSON = async (response) => ({
body: await response.json(),
contentType: response.headers.get('content-type'),
status: response.status,
})

it('automatically parses and formats JSON', async () => {
expect(await toJSON(NextResponse.json({ message: 'hello!' }))).toMatchObject({
contentType: 'application/json',
body: { message: 'hello!' },
})

expect(
await toJSON(NextResponse.json({ status: 'success' }, { status: 201 }))
).toMatchObject({
contentType: 'application/json',
body: { status: 'success' },
status: 201,
})

expect(
await toJSON(
NextResponse.json({ error: { code: 'bad_request' } }, { status: 400 })
)
).toMatchObject({
contentType: 'application/json',
body: { error: { code: 'bad_request' } },
status: 400,
})

expect(await toJSON(NextResponse.json(null))).toMatchObject({
contentType: 'application/json',
body: null,
})

expect(await toJSON(NextResponse.json(''))).toMatchObject({
contentType: 'application/json',
body: '',
})
})

it('can be cloned', async () => {
const fetchResponse = await fetch('https://example.vercel.sh')
const newResponse = new NextResponse(fetchResponse.body, fetchResponse)
Expand Down

0 comments on commit ca97e7f

Please sign in to comment.