} from './componentProps'
import { Slots, initSlots, InternalSlots } from './componentSlots'
import { warn } from './warning'
-import { ErrorCodes, callWithErrorHandling } from './errorHandling'
+import { ErrorCodes, callWithAsyncErrorHandling } from './errorHandling'
import { AppContext, createAppContext, AppConfig } from './apiCreateApp'
import { Directive, validateDirectiveName } from './directives'
import {
currentInstance = instance
pauseTracking()
- const setupResult = callWithErrorHandling(
+ const setupResult = callWithAsyncErrorHandling(
setup,
instance,
ErrorCodes.SETUP_FUNCTION,
expect(html).toBe(`<div>hello</div>`)
})
+ // #2763
+ test('error handling w/ async setup', async () => {
+ const fn = jest.fn()
+ const fn2 = jest.fn()
+
+ const asyncChildren = defineComponent({
+ async setup() {
+ return Promise.reject('async child error')
+ },
+ template: `<div>asyncChildren</div>`
+ })
+ const app = createApp({
+ name: 'App',
+ components: {
+ asyncChildren
+ },
+ template: `<div class="app"><async-children /></div>`,
+ errorCaptured(error) {
+ fn(error)
+ }
+ })
+
+ app.config.errorHandler = error => {
+ fn2(error)
+ }
+
+ const html = await renderToString(app)
+ expect(html).toBe(`<div class="app"><div>asyncChildren</div></div>`)
+
+ expect(fn).toHaveBeenCalledTimes(1)
+ expect(fn).toBeCalledWith('async child error')
+
+ expect(fn2).toHaveBeenCalledTimes(1)
+ expect(fn2).toBeCalledWith('async child error')
+
+ expect('Uncaught error in async setup').toHaveBeenWarned()
+ })
+
// https://github.com/vuejs/vue-next/issues/3322
test('effect onInvalidate does not error', async () => {
const noop = () => {}
expect(await renderToString(createApp(Comp))).toBe(`<!---->`)
expect('Uncaught error in async setup').toHaveBeenWarned()
+ expect(
+ 'Unhandled error during execution of setup function'
+ ).toHaveBeenWarned()
expect('missing template').toHaveBeenWarned()
})
`<div><div>async</div><!----></div>`
)
expect('Uncaught error in async setup').toHaveBeenWarned()
+ expect(
+ 'Unhandled error during execution of setup function'
+ ).toHaveBeenWarned()
expect('missing template or render function').toHaveBeenWarned()
})
`<div><div>async</div><div><!----></div></div>`
)
expect('Uncaught error in async setup').toHaveBeenWarned()
+ expect(
+ 'Unhandled error during execution of setup function'
+ ).toHaveBeenWarned()
expect('missing template').toHaveBeenWarned()
})
`<div><!----><div><div>async</div></div></div>`
)
expect('Uncaught error in async setup').toHaveBeenWarned()
+ expect(
+ 'Unhandled error during execution of setup function'
+ ).toHaveBeenWarned()
expect('missing template').toHaveBeenWarned()
})
})