Nuxt/test/error.test.js

81 lines
2.4 KiB
JavaScript
Raw Normal View History

2018-03-18 19:31:32 +00:00
// import rp from 'request-promise-native'
import { Nuxt, Builder } from '..'
2018-03-16 16:12:06 +00:00
import { loadConfig } from './helpers/config'
2017-06-14 18:51:14 +00:00
2017-05-21 19:00:01 +00:00
const port = 4005
2018-01-13 05:22:11 +00:00
const url = route => 'http://localhost:' + port + route
2016-12-20 18:25:51 +00:00
let nuxt = null
2018-03-18 19:31:32 +00:00
// let logSpy
2016-12-20 18:25:51 +00:00
2018-03-18 19:31:32 +00:00
describe('error', () => {
// Init nuxt.js and create server listening on localhost:4000
beforeAll(async () => {
const config = loadConfig('error', { dev: false })
2017-06-20 11:44:47 +00:00
2018-01-27 15:29:42 +00:00
nuxt = new Nuxt(config)
2018-03-18 19:31:32 +00:00
new Builder(nuxt).build()
await nuxt.listen(port, 'localhost')
2018-03-18 19:31:32 +00:00
}, 30000)
2018-03-18 19:31:32 +00:00
test('/ should display an error', async () => {
await expect(nuxt.renderRoute('/')).rejects.toMatchObject({
message: expect.stringContaining('not_defined is not defined')
})
})
2016-12-20 18:25:51 +00:00
2018-03-18 19:31:32 +00:00
test('/404 should display an error too', async () => {
let { error } = await nuxt.renderRoute('/404')
expect(error.message.includes('This page could not be found')).toBe(true)
})
2016-12-20 18:25:51 +00:00
2018-03-18 19:31:32 +00:00
test('/ with renderAndGetWindow()', async () => {
// const errorSpy = await interceptError()
await expect(nuxt.renderAndGetWindow(url('/'))).rejects.toMatchObject({
statusCode: 500
})
2016-12-20 18:25:51 +00:00
2018-03-18 19:31:32 +00:00
// release()
// expect(errorSpy.calledOnce).toBe(true)
// expect(errorSpy
// .getCall(0)
// .args[0].message.includes(
// 'render function or template not defined in component: anonymous'
// )).toBe(true)
})
2016-12-20 18:25:51 +00:00
2018-03-18 19:31:32 +00:00
// test('/ with text/json content', async () => {
// const opts = {
// headers: {
// accept: 'application/json'
// },
// resolveWithFullResponse: true
// }
// const errorSpy = await interceptError()
// const { response: { headers } } = await expect(rp(url('/'), opts)).toThrow()
// expect(headers['content-type']).toBe('text/json; charset=utf-8')
// release()
// expect(errorSpy.calledOnce).toBe(true)
// expect(errorSpy
// .getCall(0)
// .args[0].message.includes(
// 'render function or template not defined in component: anonymous'
// )).toBe(true)
// })
2017-12-07 08:12:22 +00:00
2018-03-18 19:31:32 +00:00
// test('Deprecated: dev in build.extend()', async () => {
// expect(logSpy.calledWith('[build:done]: hook error')).toBe(true)
// })
2018-01-27 15:29:42 +00:00
2018-03-18 19:31:32 +00:00
test('Error: resolvePath()', async () => {
expect(() => nuxt.resolvePath()).toThrowError(TypeError)
2018-01-29 03:41:56 +00:00
2018-03-18 19:31:32 +00:00
expect(() => nuxt.resolvePath('@/pages/about.vue')).toThrowError('Cannot resolve "@/pages/about.vue"')
})
2018-01-29 03:41:56 +00:00
2018-03-18 19:31:32 +00:00
// Close server and ask nuxt to stop listening to file changes
test('Closing server and nuxt.js', async () => {
await nuxt.close()
})
2016-12-20 18:25:51 +00:00
})