refactor(runtime-core): adjust error handling behavior
- Crash in dev to make the errors more noticeable - Recover in prod to reduce impact on end users
This commit is contained in:
@@ -10,17 +10,8 @@ import {
|
||||
defineComponent,
|
||||
watchEffect
|
||||
} from '@vue/runtime-test'
|
||||
import { setErrorRecovery } from '../src/errorHandling'
|
||||
|
||||
describe('error handling', () => {
|
||||
beforeEach(() => {
|
||||
setErrorRecovery(true)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
setErrorRecovery(false)
|
||||
})
|
||||
|
||||
test('propagation', () => {
|
||||
const err = new Error('foo')
|
||||
const fn = jest.fn()
|
||||
@@ -470,8 +461,6 @@ describe('error handling', () => {
|
||||
})
|
||||
|
||||
it('should warn unhandled', () => {
|
||||
const onError = jest.spyOn(console, 'error')
|
||||
onError.mockImplementation(() => {})
|
||||
const groupCollapsed = jest.spyOn(console, 'groupCollapsed')
|
||||
groupCollapsed.mockImplementation(() => {})
|
||||
const log = jest.spyOn(console, 'log')
|
||||
@@ -496,14 +485,18 @@ describe('error handling', () => {
|
||||
render() {}
|
||||
}
|
||||
|
||||
render(h(Comp), nodeOps.createElement('div'))
|
||||
let caughtError
|
||||
try {
|
||||
render(h(Comp), nodeOps.createElement('div'))
|
||||
} catch (caught) {
|
||||
caughtError = caught
|
||||
}
|
||||
expect(fn).toHaveBeenCalledWith(err, 'setup function')
|
||||
expect(
|
||||
`Unhandled error during execution of setup function`
|
||||
).toHaveBeenWarned()
|
||||
expect(onError).toHaveBeenCalledWith(err)
|
||||
expect(caughtError).toBe(err)
|
||||
|
||||
onError.mockRestore()
|
||||
groupCollapsed.mockRestore()
|
||||
log.mockRestore()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user