mirror of
https://gitee.com/vuejs/vue.git
synced 2024-12-04 13:07:40 +08:00
config.errorHandler should capture user wathcer errors too (ref #3142)
This commit is contained in:
parent
194b20a9dc
commit
76d7809a11
@ -188,7 +188,24 @@ export default class Watcher {
|
||||
// set new value
|
||||
const oldValue = this.value
|
||||
this.value = value
|
||||
this.cb.call(this.vm, value, oldValue)
|
||||
if (this.user) {
|
||||
try {
|
||||
this.cb.call(this.vm, value, oldValue)
|
||||
} catch (e) {
|
||||
process.env.NODE_ENV !== 'production' && warn(
|
||||
`Error in watcher "${this.expression}"`,
|
||||
this.vm
|
||||
)
|
||||
/* istanbul ignore else */
|
||||
if (config.errorHandler) {
|
||||
config.errorHandler.call(null, e, this.vm)
|
||||
} else {
|
||||
throw e
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.cb.call(this.vm, value, oldValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,25 @@ describe('Global config', () => {
|
||||
expect(spy).toHaveBeenCalledWith(err, vm)
|
||||
Vue.config.errorHandler = null
|
||||
})
|
||||
|
||||
it('should capture user watcher callback errors', done => {
|
||||
const spy = jasmine.createSpy('errorHandler')
|
||||
Vue.config.errorHandler = spy
|
||||
const err = new Error()
|
||||
const vm = new Vue({
|
||||
data: { a: 1 },
|
||||
watch: {
|
||||
a: () => {
|
||||
throw err
|
||||
}
|
||||
}
|
||||
}).$mount()
|
||||
vm.a = 2
|
||||
waitForUpdate(() => {
|
||||
expect(spy).toHaveBeenCalledWith(err, vm)
|
||||
Vue.config.errorHandler = null
|
||||
}).then(done)
|
||||
})
|
||||
})
|
||||
|
||||
describe('optionMergeStrategies', () => {
|
||||
|
Loading…
Reference in New Issue
Block a user