mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
test: error in callHook
This commit is contained in:
parent
0aa6e9b2bf
commit
68560c6aae
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user