Unverified Commit 004ad62d authored by Roko Bekavac's avatar Roko Bekavac Committed by GitHub

Allow `undefined` body sent to `sendData()` (#20981)

Co-authored-by: 's avatarrokobekavac0 <roko.beakavac2003@gmail.com>
Co-authored-by: 's avatarTim Neutkens <tim@timneutkens.nl>
Co-authored-by: 's avatarJoe Haddad <joe.haddad@zeit.co>
parent 07d4af93
......@@ -231,7 +231,7 @@ export function sendData(
res: NextApiResponse,
body: any
): void {
if (body === null) {
if (body === null || body === undefined) {
res.end()
return
}
......
export default (req, res) => {
res.json(undefined)
}
......@@ -122,6 +122,12 @@ function runTests(dev = false) {
expect(body).toBe(true)
})
it('should support undefined response body', async () => {
const res = await fetchViaHTTP(appPort, '/api/undefined', null, {})
const body = res.ok ? await res.text() : null
expect(body).toBe('')
})
it('should return error with invalid JSON', async () => {
const data = await fetchViaHTTP(appPort, '/api/parse', null, {
method: 'POST',
......
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