File tree Expand file tree Collapse file tree
packages/vue-query/src/__tests__ Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -420,5 +420,27 @@ describe('useMutation', () => {
420420 expect ( boundaryFn ) . toHaveBeenCalledTimes ( 1 )
421421 expect ( boundaryFn ) . toHaveBeenCalledWith ( err )
422422 } )
423+
424+ test ( 'should throw from error watcher when throwOnError returns true' , async ( ) => {
425+ const throwOnErrorFn = vi . fn ( ) . mockReturnValue ( true )
426+ const { mutate } = useMutation ( {
427+ mutationFn : ( ) =>
428+ sleep ( 10 ) . then ( ( ) => Promise . reject ( new Error ( 'Some error' ) ) ) ,
429+ throwOnError : throwOnErrorFn ,
430+ } )
431+
432+ mutate ( )
433+
434+ // Suppress the Unhandled Rejection caused by watcher throw in Vue 3
435+ const rejectionHandler = ( ) => { }
436+ process . on ( 'unhandledRejection' , rejectionHandler )
437+
438+ await vi . advanceTimersByTimeAsync ( 10 )
439+
440+ process . off ( 'unhandledRejection' , rejectionHandler )
441+
442+ expect ( throwOnErrorFn ) . toHaveBeenCalledTimes ( 1 )
443+ expect ( throwOnErrorFn ) . toHaveBeenCalledWith ( Error ( 'Some error' ) )
444+ } )
423445 } )
424446} )
You can’t perform that action at this time.
0 commit comments