watch,
ref,
nextTick,
- mockWarn
+ mockWarn,
+ createComponent
} from '@vue/runtime-test'
describe('error handling', () => {
expect(fn).toHaveBeenCalledWith(err, 'render function')
})
+ test('in function ref', () => {
+ const err = new Error('foo')
+ const ref = () => {
+ throw err
+ }
+ const fn = jest.fn()
+
+ const Comp = {
+ setup() {
+ onErrorCaptured((err, instance, info) => {
+ fn(err, info)
+ return true
+ })
+ return () => h(Child)
+ }
+ }
+
+ const Child = createComponent(() => () => h('div', { ref }))
+
+ render(h(Comp), nodeOps.createElement('div'))
+ expect(fn).toHaveBeenCalledWith(err, 'ref function')
+ })
+
test('in watch (simple usage)', () => {
const err = new Error('foo')
const fn = jest.fn()
createSuspenseBoundary,
normalizeSuspenseChildren
} from './suspense'
-import { handleError, ErrorCodes } from './errorHandling'
+import { handleError, ErrorCodes, callWithErrorHandling } from './errorHandling'
const prodEffectOptions = {
scheduler: queueJob
} else if (isRef(ref)) {
ref.value = value
} else if (isFunction(ref)) {
- ref(value, refs)
+ callWithErrorHandling(ref, parent, ErrorCodes.FUNCTION_REF, [value, refs])
} else if (__DEV__) {
warn('Invalid template ref type:', value, `(${typeof value})`)
}
DIRECTIVE_HOOK,
APP_ERROR_HANDLER,
APP_WARN_HANDLER,
+ FUNCTION_REF,
SCHEDULER
}
[ErrorCodes.DIRECTIVE_HOOK]: 'directive hook',
[ErrorCodes.APP_ERROR_HANDLER]: 'app errorHandler',
[ErrorCodes.APP_WARN_HANDLER]: 'app warnHandler',
+ [ErrorCodes.FUNCTION_REF]: 'ref function',
[ErrorCodes.SCHEDULER]:
'scheduler flush. This is likely a Vue internals bug. ' +
'Please open an issue at https://new-issue.vuejs.org/?repo=vuejs/vue'