mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-05 21:53:56 +00:00
b4d81dc584
* lint: require await in async function * lint: replace "error" with 2 in config
63 lines
1.8 KiB
JavaScript
63 lines
1.8 KiB
JavaScript
// import rp from 'request-promise-native'
|
|
import consola from 'consola'
|
|
import { loadFixture, getPort, Nuxt } from '../utils'
|
|
|
|
let port
|
|
const url = route => 'http://localhost:' + port + route
|
|
|
|
let nuxt = null
|
|
// let logSpy
|
|
|
|
describe('error', () => {
|
|
beforeAll(async () => {
|
|
const config = loadFixture('error')
|
|
nuxt = new Nuxt(config)
|
|
port = await getPort()
|
|
await nuxt.listen(port, 'localhost')
|
|
})
|
|
|
|
test('/ should display an error', async () => {
|
|
await expect(nuxt.renderRoute('/')).rejects.toMatchObject({
|
|
message: expect.stringContaining('not_defined is not defined')
|
|
})
|
|
})
|
|
|
|
test('/404 should display an error too', async () => {
|
|
const { error } = await nuxt.renderRoute('/404')
|
|
expect(error.message.includes('This page could not be found')).toBe(true)
|
|
})
|
|
|
|
test('/ with renderAndGetWindow()', async () => {
|
|
await expect(nuxt.renderAndGetWindow(url('/'))).rejects.toMatchObject({
|
|
statusCode: 500
|
|
})
|
|
})
|
|
|
|
test('Error: resolvePath()', () => {
|
|
expect(() => nuxt.resolvePath()).toThrowError()
|
|
expect(() => nuxt.resolvePath('@/pages/about.vue')).toThrowError('Cannot resolve "@/pages/about.vue"')
|
|
})
|
|
|
|
test('Error: callHook()', async () => {
|
|
const errorHook = jest.fn()
|
|
const error = new Error('test hook error')
|
|
jest.spyOn(consola, 'error')
|
|
|
|
nuxt.hook('error', errorHook)
|
|
nuxt.hook('test:error', () => { throw error })
|
|
await nuxt.callHook('test:error')
|
|
|
|
expect(errorHook).toHaveBeenCalledTimes(1)
|
|
expect(errorHook).toHaveBeenCalledWith(error)
|
|
expect(consola.error).toHaveBeenCalledTimes(1)
|
|
expect(consola.error).toHaveBeenCalledWith(error)
|
|
|
|
consola.error.mockRestore()
|
|
})
|
|
|
|
// Close server and ask nuxt to stop listening to file changes
|
|
afterAll(async () => {
|
|
await nuxt.close()
|
|
})
|
|
})
|