Skip to content

Commit b4517ab

Browse files
authored
fix: remove throw from errorHandler (#655)
1 parent 9a2a25a commit b4517ab

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

Diff for: packages/test-utils/src/mount.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,16 @@ import { addScopedSlots } from './add-scoped-slots'
1616

1717
Vue.config.productionTip = false
1818
Vue.config.devtools = false
19-
Vue.config.errorHandler = errorHandler
2019

2120
export default function mount (component: Component, options: Options = {}): VueWrapper {
21+
const existingErrorHandler = Vue.config.errorHandler
22+
Vue.config.errorHandler = errorHandler
23+
2224
warnIfNoWindow()
2325

26+
// Remove cached constructor
27+
delete component._Ctor
28+
2429
const vueConstructor = options.localVue || createLocalVue()
2530

2631
const elm = options.attachToDocument
@@ -57,6 +62,8 @@ export default function mount (component: Component, options: Options = {}): Vue
5762
throw (componentsWithError[0]._error)
5863
}
5964

65+
Vue.config.errorHandler = existingErrorHandler
66+
6067
const wrapperOptions = {
6168
attachedToDocument: !!mergedOptions.attachToDocument,
6269
sync: mergedOptions.sync

Diff for: test/specs/mount.spec.js

+34
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,40 @@ describeRunIf(process.env.TEST_ENV !== 'node',
227227
expect(fn).to.throw('Error in mounted')
228228
})
229229

230+
itDoNotRunIf(
231+
vueVersion < 2.2,
232+
'logs errors once after mount', (done) => {
233+
Vue.config.errorHandler = null
234+
const TestComponent = {
235+
template: '<div/>',
236+
updated: function () {
237+
throw new Error('Error in updated')
238+
}
239+
}
240+
241+
const wrapper = mount(TestComponent, {
242+
sync: false
243+
})
244+
wrapper.vm.$forceUpdate()
245+
setTimeout(() => {
246+
vueVersion > 2.1
247+
? expect(console.error).calledTwice
248+
: expect(console.error).calledOnce
249+
done()
250+
})
251+
})
252+
253+
it('restores user error handler after mount', () => {
254+
const existingErrorHandler = () => {}
255+
Vue.config.errorHandler = existingErrorHandler
256+
const TestComponent = {
257+
template: '<div/>'
258+
}
259+
mount(TestComponent)
260+
expect(Vue.config.errorHandler).to.equal(existingErrorHandler)
261+
Vue.config.errorHandler = null
262+
})
263+
230264
it('overwrites the component options with the options other than the mounting options when the options for mount contain those', () => {
231265
const Component = {
232266
template: '<div>{{ foo() }}{{ bar() }}{{ baz() }}</div>',

0 commit comments

Comments
 (0)