test: request of error accepts JSON

This commit is contained in:
Clark Du 2017-12-07 16:12:22 +08:00 committed by Pooya Parsa
parent 2c52a8bc5a
commit 4cafca0fec
2 changed files with 23 additions and 0 deletions

View File

@ -38,6 +38,17 @@ test('/test/error should return error stack trace (Youch)', async t => {
t.true(error.includes('<div class="error-frames">')) t.true(error.includes('<div class="error-frames">'))
}) })
test('/test/error should return json format error (Youch)', async t => {
const opts = {
headers: {
'accept': 'application/json'
},
resolveWithFullResponse: true
}
const { response: { headers } } = await t.throws(rp(url('/test/error'), opts))
t.is(headers['content-type'], 'text/json; charset=utf-8')
})
// Close server and ask nuxt to stop listening to file changes // Close server and ask nuxt to stop listening to file changes
test.after('Closing server and nuxt.js', t => { test.after('Closing server and nuxt.js', t => {
nuxt.close() nuxt.close()

View File

@ -1,5 +1,6 @@
import test from 'ava' import test from 'ava'
import { resolve } from 'path' import { resolve } from 'path'
import rp from 'request-promise-native'
import { Nuxt, Builder } from '../index.js' import { Nuxt, Builder } from '../index.js'
const port = 4005 const port = 4005
@ -38,6 +39,17 @@ test('/ with renderAndGetWindow()', async t => {
t.is(err.response.statusMessage, 'NuxtServerError') t.is(err.response.statusMessage, 'NuxtServerError')
}) })
test('/ with text/json content', async t => {
const opts = {
headers: {
'accept': 'application/json'
},
resolveWithFullResponse: true
}
const { response: { headers } } = await t.throws(rp(url('/'), opts))
t.is(headers['content-type'], 'text/json; charset=utf-8')
})
// Close server and ask nuxt to stop listening to file changes // Close server and ask nuxt to stop listening to file changes
test.after('Closing server and nuxt.js', t => { test.after('Closing server and nuxt.js', t => {
nuxt.close() nuxt.close()