fix(runtime-core): error handling for created/beforeCreate hooks

fix #2268
This commit is contained in:
Evan You
2020-10-07 16:58:19 -04:00
parent d744b8a2dc
commit b392fe419c
2 changed files with 66 additions and 15 deletions

View File

@@ -181,6 +181,41 @@ describe('error handling', () => {
expect(fn).toHaveBeenCalledWith(err, 'setup function')
})
// unlike other lifecycle hooks, created/beforeCreate are called as part of
// the options API initiualization process instead of by the renderer.
test('in created/beforeCreate hook', () => {
const err = new Error('foo')
const fn = jest.fn()
const Comp = {
setup() {
onErrorCaptured((err, instance, info) => {
fn(err, info)
return false
})
return () => [h(Child1), h(Child2)]
}
}
const Child1 = {
created() {
throw err
},
render() {}
}
const Child2 = {
beforeCreate() {
throw err
},
render() {}
}
render(h(Comp), nodeOps.createElement('div'))
expect(fn).toHaveBeenCalledWith(err, 'created hook')
expect(fn).toHaveBeenCalledWith(err, 'beforeCreate hook')
})
test('in render function', () => {
const err = new Error('foo')
const fn = jest.fn()