test: error in callHook

This commit is contained in:
Clark Du 2018-04-18 22:36:23 +08:00
parent 0aa6e9b2bf
commit 68560c6aae
No known key found for this signature in database
GPG Key ID: D0E5986AF78B86D9

View File

@ -1,4 +1,5 @@
// import rp from 'request-promise-native'
import consola from 'consola'
import { loadFixture, getPort, Nuxt } from '../utils'
let port
@ -38,6 +39,23 @@ describe('error', () => {
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()