diff --git a/packages/test-utils/src/error.js b/packages/test-utils/src/error.js
index dc2ba1a53..c6da3b723 100644
--- a/packages/test-utils/src/error.js
+++ b/packages/test-utils/src/error.js
@@ -22,13 +22,14 @@ function errorHandler(errorOrString, vm, info) {
vm._error = error
}
+ if (!instancedErrorHandlers.length) {
+ throw error
+ }
// should be one error handler, as only once can be registered with local vue
// regardless, if more exist (for whatever reason), invoke the other user defined error handlers
instancedErrorHandlers.forEach(instancedErrorHandler => {
instancedErrorHandler(error, vm, info)
})
-
- throw error
}
export function throwIfInstancesThrew(vm) {
diff --git a/test/specs/create-local-vue.spec.js b/test/specs/create-local-vue.spec.js
index 6164f3a66..72bfd57b1 100644
--- a/test/specs/create-local-vue.spec.js
+++ b/test/specs/create-local-vue.spec.js
@@ -151,6 +151,66 @@ describeWithShallowAndMount('createLocalVue', mountingMethod => {
}
)
+ itSkipIf(
+ vueVersion < 2.6,
+ 'Exception suppresed in `errorHandler` is not logged to console.error',
+ async () => {
+ const component = Vue.component('TestComponent', {
+ template: '',
+ methods: {
+ clickHandler() {
+ throw new Error('Should not be logged')
+ }
+ }
+ })
+ const errorHandler = jest.fn()
+ const localVue = createLocalVue({
+ errorHandler
+ })
+ const wrapper = mountingMethod(component, { localVue })
+ await wrapper.vm.$nextTick()
+
+ const { error } = global.console
+ const spy = jest.spyOn(global.console, 'error')
+ await wrapper.trigger('click')
+ global.console.error = error
+ expect(spy).not.toHaveBeenCalled()
+ }
+ )
+
+ itSkipIf(
+ vueVersion < 2.6,
+ 'Exception raised in `errorHandler` bubbles up',
+ async () => {
+ const component = Vue.component('TestComponent', {
+ template: '',
+ methods: {
+ clickHandler() {
+ throw new Error()
+ }
+ }
+ })
+ const errorHandler = (err, vm, info) => {
+ if (err) {
+ throw new Error('An error that should log')
+ }
+ }
+ const localVue = createLocalVue({
+ errorHandler
+ })
+ const wrapper = mountingMethod(component, { localVue })
+ await wrapper.vm.$nextTick()
+
+ const { error } = global.console
+ const spy = jest.spyOn(global.console, 'error')
+ await wrapper.trigger('click')
+ global.console.error = error
+ expect(spy).toHaveBeenCalledWith(
+ '[Vue warn]: Error in config.errorHandler: "Error: An error that should log"'
+ )
+ }
+ )
+
itSkipIf(
process.env.TEST_ENV === 'browser' || vueVersion < 2.6,
'Calls `errorHandler` when an error is thrown asynchronously',