Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/mount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -100,9 +100,9 @@ export function mount(
to.appendChild(el)
}
const vm = app.mount(el)

if (errorOnMount) {
throw errorOnMount
if (errorsOnMount.length) {
// If an error is thrown, throw the first error.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: // If several errors are thrown during mount, then throw the first one

throw errorsOnMount[0]
}
app.config.errorHandler = originalErrorHandler

Expand Down
9 changes: 9 additions & 0 deletions tests/mount.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,16 @@ describe('mount: general tests', () => {

expect(wrapper.html()).toBe('<div>hello</div>')
})
it('if an error is thrown during mounting, the first error is thrown.', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can you name the test with the usual convention should...? For example should throw the first error encountered when mounting the component.
Can you also add an empty line above and below the test as we usually do?

const ThrowingComponent = defineComponent({
setup() {
throw new Error('Boom!')
},
template: '<div>{{ x.y }}</div>'
})

expect(() => mount(ThrowingComponent)).toThrowError('Boom!')
})
it('should not warn on readonly hasOwnProperty when mounting a component', () => {
const spy = vi.spyOn(console, 'warn').mockImplementation(() => {})

Expand Down