File tree 2 files changed +16
-5
lines changed
2 files changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -74,9 +74,9 @@ export function mount(
74
74
// Workaround for https://github.com/vuejs/core/issues/7020
75
75
const originalErrorHandler = app . config . errorHandler
76
76
77
- let errorOnMount = null
77
+ let errorsOnMount : unknown [ ] = [ ]
78
78
app . config . errorHandler = ( err , instance , info ) => {
79
- errorOnMount = err
79
+ errorsOnMount . push ( err )
80
80
81
81
return originalErrorHandler ?.( err , instance , info )
82
82
}
@@ -100,9 +100,9 @@ export function mount(
100
100
to . appendChild ( el )
101
101
}
102
102
const vm = app . mount ( el )
103
-
104
- if ( errorOnMount ) {
105
- throw errorOnMount
103
+ if ( errorsOnMount . length ) {
104
+ // If several errors are thrown during mount, then throw the first one
105
+ throw errorsOnMount [ 0 ]
106
106
}
107
107
app . config . errorHandler = originalErrorHandler
108
108
Original file line number Diff line number Diff line change @@ -28,6 +28,17 @@ describe('mount: general tests', () => {
28
28
expect ( wrapper . html ( ) ) . toBe ( '<div>hello</div>' )
29
29
} )
30
30
31
+ it ( 'should throw the first error encountered when mounting the component' , ( ) => {
32
+ const ThrowingComponent = defineComponent ( {
33
+ setup ( ) {
34
+ throw new Error ( 'Boom!' )
35
+ } ,
36
+ template : '<div>{{ x.y }}</div>'
37
+ } )
38
+
39
+ expect ( ( ) => mount ( ThrowingComponent ) ) . toThrowError ( 'Boom!' )
40
+ } )
41
+
31
42
it ( 'should not warn on readonly hasOwnProperty when mounting a component' , ( ) => {
32
43
const spy = vi . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => { } )
33
44
You can’t perform that action at this time.
0 commit comments