File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -574,9 +574,24 @@ export function mount(
574
574
}
575
575
}
576
576
577
+ // Workaround for https://github.com/vuejs/core/issues/7020
578
+ const originalErrorHandler = app . config . errorHandler
579
+
580
+ let errorOnMount = null
581
+ app . config . errorHandler = ( err , instance , info ) => {
582
+ errorOnMount = err
583
+
584
+ return originalErrorHandler ?.( err , instance , info )
585
+ }
586
+
577
587
// mount the app!
578
588
const vm = app . mount ( el )
579
589
590
+ if ( errorOnMount ) {
591
+ throw errorOnMount
592
+ }
593
+ app . config . errorHandler = originalErrorHandler
594
+
580
595
const appRef = componentRef . value ! as ComponentPublicInstance
581
596
// we add `hasOwnProperty` so Jest can spy on the proxied vm without throwing
582
597
// note that this is not necessary with Jest v27+ or Vitest, but is kept for compatibility with older Jest versions
Original file line number Diff line number Diff line change
1
+ import { describe , expect , it } from 'vitest'
2
+ import { defineComponent } from 'vue'
3
+ import { mount } from '../src'
4
+
5
+ describe ( 'mount: general tests' , ( ) => {
6
+ it ( 'correctly handles component, throwing on mount' , ( ) => {
7
+ // See https://github.com/vuejs/core/issues/7020
8
+ const ThrowingComponent = defineComponent ( {
9
+ props : [ 'blowup' ] ,
10
+ mounted ( ) {
11
+ if ( this . blowup ) {
12
+ throw new Error ( 'Boom!' )
13
+ }
14
+ } ,
15
+ template : '<div>hello</div>'
16
+ } )
17
+
18
+ expect ( ( ) =>
19
+ mount ( ThrowingComponent , { props : { blowup : true } } )
20
+ ) . toThrow ( )
21
+
22
+ const wrapper = mount ( ThrowingComponent , { props : { blowup : false } } )
23
+
24
+ expect ( wrapper . html ( ) ) . toBe ( '<div>hello</div>' )
25
+ } )
26
+ } )
You can’t perform that action at this time.
0 commit comments