diff --git a/packages/test-utils/src/mount.js b/packages/test-utils/src/mount.js index 90f5ced00..6d265532c 100644 --- a/packages/test-utils/src/mount.js +++ b/packages/test-utils/src/mount.js @@ -16,11 +16,16 @@ import { addScopedSlots } from './add-scoped-slots' Vue.config.productionTip = false Vue.config.devtools = false -Vue.config.errorHandler = errorHandler export default function mount (component: Component, options: Options = {}): VueWrapper { + const existingErrorHandler = Vue.config.errorHandler + Vue.config.errorHandler = errorHandler + warnIfNoWindow() + // Remove cached constructor + delete component._Ctor + const vueConstructor = options.localVue || createLocalVue() const elm = options.attachToDocument @@ -57,6 +62,8 @@ export default function mount (component: Component, options: Options = {}): Vue throw (componentsWithError[0]._error) } + Vue.config.errorHandler = existingErrorHandler + const wrapperOptions = { attachedToDocument: !!mergedOptions.attachToDocument, sync: mergedOptions.sync diff --git a/test/specs/mount.spec.js b/test/specs/mount.spec.js index 2080dcc90..15e40908c 100644 --- a/test/specs/mount.spec.js +++ b/test/specs/mount.spec.js @@ -227,6 +227,40 @@ describeRunIf(process.env.TEST_ENV !== 'node', expect(fn).to.throw('Error in mounted') }) + itDoNotRunIf( + vueVersion < 2.2, + 'logs errors once after mount', (done) => { + Vue.config.errorHandler = null + const TestComponent = { + template: '
', + updated: function () { + throw new Error('Error in updated') + } + } + + const wrapper = mount(TestComponent, { + sync: false + }) + wrapper.vm.$forceUpdate() + setTimeout(() => { + vueVersion > 2.1 + ? expect(console.error).calledTwice + : expect(console.error).calledOnce + done() + }) + }) + + it('restores user error handler after mount', () => { + const existingErrorHandler = () => {} + Vue.config.errorHandler = existingErrorHandler + const TestComponent = { + template: '
' + } + mount(TestComponent) + expect(Vue.config.errorHandler).to.equal(existingErrorHandler) + Vue.config.errorHandler = null + }) + it('overwrites the component options with the options other than the mounting options when the options for mount contain those', () => { const Component = { template: '
{{ foo() }}{{ bar() }}{{ baz() }}
',