diff --git a/test/unit/error.test.js b/test/unit/error.test.js index 56c4291f8e..d3a3bade54 100644 --- a/test/unit/error.test.js +++ b/test/unit/error.test.js @@ -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()