File tree 2 files changed +31
-2
lines changed
2 files changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,9 @@ import {
16
16
cloneVNode ,
17
17
provide ,
18
18
defineAsyncComponent ,
19
- Component
19
+ Component ,
20
+ createApp ,
21
+ onActivated
20
22
} from '@vue/runtime-test'
21
23
import { KeepAliveProps } from '../../src/components/KeepAlive'
22
24
@@ -874,4 +876,31 @@ describe('KeepAlive', () => {
874
876
await nextTick ( )
875
877
expect ( serializeInner ( root ) ) . toBe ( '<p>1</p>' )
876
878
} )
879
+
880
+ // #4976
881
+ test ( 'handle error in async onActivated' , async ( ) => {
882
+ const err = new Error ( 'foo' )
883
+ const handler = jest . fn ( )
884
+
885
+ const app = createApp ( {
886
+ setup ( ) {
887
+ return ( ) => h ( KeepAlive , null , ( ) => h ( Child ) )
888
+ }
889
+ } )
890
+
891
+ const Child = {
892
+ setup ( ) {
893
+ onActivated ( async ( ) => {
894
+ throw err
895
+ } )
896
+ } ,
897
+ render ( ) { }
898
+ }
899
+
900
+ app . config . errorHandler = handler
901
+ app . mount ( nodeOps . createElement ( 'div' ) )
902
+
903
+ await nextTick ( )
904
+ expect ( handler ) . toHaveBeenCalledWith ( err , { } , 'activated hook' )
905
+ } )
877
906
} )
Original file line number Diff line number Diff line change @@ -381,7 +381,7 @@ function registerKeepAliveHook(
381
381
}
382
382
current = current . parent
383
383
}
384
- hook ( )
384
+ return hook ( )
385
385
} )
386
386
injectHook ( type , wrappedHook , target )
387
387
// In addition to registering it on the target instance, we walk up the parent
You can’t perform that action at this time.
0 commit comments