diff --git a/src/mount.ts b/src/mount.ts index 327ffd509..4e1027d35 100644 --- a/src/mount.ts +++ b/src/mount.ts @@ -74,9 +74,9 @@ export function mount( // Workaround for https://github.com/vuejs/core/issues/7020 const originalErrorHandler = app.config.errorHandler - let errorOnMount = null + let errorsOnMount: unknown[] = [] app.config.errorHandler = (err, instance, info) => { - errorOnMount = err + errorsOnMount.push(err) return originalErrorHandler?.(err, instance, info) } @@ -100,9 +100,9 @@ export function mount( to.appendChild(el) } const vm = app.mount(el) - - if (errorOnMount) { - throw errorOnMount + if (errorsOnMount.length) { + // If several errors are thrown during mount, then throw the first one + throw errorsOnMount[0] } app.config.errorHandler = originalErrorHandler diff --git a/tests/mount.spec.ts b/tests/mount.spec.ts index dc6d71536..e3a3dccba 100644 --- a/tests/mount.spec.ts +++ b/tests/mount.spec.ts @@ -28,6 +28,17 @@ describe('mount: general tests', () => { expect(wrapper.html()).toBe('
hello
') }) + it('should throw the first error encountered when mounting the component', () => { + const ThrowingComponent = defineComponent({ + setup() { + throw new Error('Boom!') + }, + template: '
{{ x.y }}
' + }) + + expect(() => mount(ThrowingComponent)).toThrowError('Boom!') + }) + it('should not warn on readonly hasOwnProperty when mounting a component', () => { const spy = vi.spyOn(console, 'warn').mockImplementation(() => {})