Skip to content

Commit eb893c8

Browse files
committed
Remove error handler after mount
1 parent 032a7a4 commit eb893c8

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@ import warnIfNoWindow from './warn-if-no-window'
1515

1616
Vue.config.productionTip = false
1717
Vue.config.devtools = false
18-
Vue.config.errorHandler = errorHandler
1918

2019
export default function mount (component: Component, options: Options = {}): VueWrapper {
20+
const existingErrorHandler = Vue.config.errorHandler
21+
Vue.config.errorHandler = errorHandler
22+
2123
warnIfNoWindow()
24+
2225
// Remove cached constructor
2326
delete component._Ctor
2427
const vueClass = options.localVue || createLocalVue()
@@ -35,6 +38,8 @@ export default function mount (component: Component, options: Options = {}): Vue
3538
throw (componentsWithError[0]._error)
3639
}
3740

41+
Vue.config.errorHandler = existingErrorHandler
42+
3843
const wrapperOptions = {
3944
attachedToDocument: !!options.attachToDocument,
4045
sync: !!((options.sync || options.sync === undefined))

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

+31
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,37 @@ describeRunIf(process.env.TEST_ENV !== 'node',
235235
expect(fn).to.throw('Error in mounted')
236236
})
237237

238+
it.only('logs errors once after mount and restores user error handler', (done) => {
239+
const TestComponent = {
240+
template: '<div/>',
241+
updated: function () {
242+
throw new Error('Error in updated')
243+
}
244+
}
245+
246+
const wrapper = mount(TestComponent, {
247+
sync: false
248+
})
249+
wrapper.vm.$forceUpdate()
250+
setTimeout(() => {
251+
expect(consoleError).calledTwice
252+
done()
253+
})
254+
})
255+
256+
it.only('restores user error handler after mount', () => {
257+
const existingErrorHandler = () => {}
258+
Vue.config.errorHandler = existingErrorHandler
259+
console.log(Vue.config.errorHandler)
260+
const TestComponent = {
261+
template: '<div/>'
262+
}
263+
264+
mount(TestComponent)
265+
266+
expect(Vue.config.errorHandler).to.equal(existingErrorHandler)
267+
})
268+
238269
it('overwrites the component options with the options other than the mounting options when the options for mount contain those', () => {
239270
const Component = {
240271
template: '<div>{{ foo() }}{{ bar() }}{{ baz() }}</div>',

0 commit comments

Comments
 (0)