Nuxt/test/error.test.js

47 lines
1.4 KiB
JavaScript
Raw Normal View History

2018-03-18 19:31:32 +00:00
// import rp from 'request-promise-native'
2018-03-18 23:41:14 +00:00
import { Nuxt } from '..'
import { loadFixture, getPort } from './utils'
2017-06-14 18:51:14 +00:00
2018-03-18 23:41:14 +00:00
let port
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', () => {
beforeAll(async () => {
2018-03-18 23:41:14 +00:00
const config = loadFixture('error')
2018-01-27 15:29:42 +00:00
nuxt = new Nuxt(config)
2018-03-18 23:41:14 +00:00
port = await getPort()
await nuxt.listen(port, 'localhost')
2018-03-18 23:41:14 +00:00
})
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
})
2018-03-19 02:14:26 +00:00
})
2016-12-20 18:25:51 +00:00
2018-03-18 19:31:32 +00:00
test('Error: resolvePath()', async () => {
2018-03-19 05:48:11 +00:00
expect(() => nuxt.resolvePath()).toThrowError('The \'request\' argument must be string')
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
})