@@ -844,10 +844,6 @@ describe('mutations', () => {
844844 } )
845845
846846 describe ( 'erroneous mutation callback' , ( ) => {
847- afterEach ( ( ) => {
848- process . removeAllListeners ( 'unhandledRejection' )
849- } )
850-
851847 test ( 'error by global onSuccess triggers onError callback' , async ( ) => {
852848 const newMutationError = new Error ( 'mutation-error' )
853849
@@ -956,7 +952,9 @@ describe('mutations', () => {
956952 expect ( mutationError ) . toEqual ( newMutationError )
957953 } )
958954
959- test ( 'error by global onSettled triggers onError callback, calling global onSettled callback twice' , async ( ) => {
955+ test ( 'error by global onSettled triggers onError callback, calling global onSettled callback twice' , async ( {
956+ onTestFinished,
957+ } ) => {
960958 const newMutationError = new Error ( 'mutation-error' )
961959
962960 queryClient = new QueryClient ( {
@@ -972,6 +970,9 @@ describe('mutations', () => {
972970
973971 const unhandledRejectionFn = vi . fn ( )
974972 process . on ( 'unhandledRejection' , ( error ) => unhandledRejectionFn ( error ) )
973+ onTestFinished ( ( ) => {
974+ process . off ( 'unhandledRejection' , unhandledRejectionFn )
975+ } )
975976
976977 const key = queryKey ( )
977978 const results : Array < string > = [ ]
@@ -1025,9 +1026,14 @@ describe('mutations', () => {
10251026 expect ( mutationError ) . toEqual ( newMutationError )
10261027 } )
10271028
1028- test ( 'error by mutations onSettled triggers onError callback, calling both onSettled callbacks twice' , async ( ) => {
1029+ test ( 'error by mutations onSettled triggers onError callback, calling both onSettled callbacks twice' , async ( {
1030+ onTestFinished,
1031+ } ) => {
10291032 const unhandledRejectionFn = vi . fn ( )
10301033 process . on ( 'unhandledRejection' , ( error ) => unhandledRejectionFn ( error ) )
1034+ onTestFinished ( ( ) => {
1035+ process . off ( 'unhandledRejection' , unhandledRejectionFn )
1036+ } )
10311037
10321038 const key = queryKey ( )
10331039 const results : Array < string > = [ ]
@@ -1084,9 +1090,14 @@ describe('mutations', () => {
10841090 expect ( mutationError ) . toEqual ( newMutationError )
10851091 } )
10861092
1087- test ( 'errors by onError and consecutive onSettled callbacks are transferred to different execution context where it are reported' , async ( ) => {
1093+ test ( 'errors by onError and consecutive onSettled callbacks are transferred to different execution context where it are reported' , async ( {
1094+ onTestFinished,
1095+ } ) => {
10881096 const unhandledRejectionFn = vi . fn ( )
10891097 process . on ( 'unhandledRejection' , ( error ) => unhandledRejectionFn ( error ) )
1098+ onTestFinished ( ( ) => {
1099+ process . off ( 'unhandledRejection' , unhandledRejectionFn )
1100+ } )
10901101
10911102 const globalErrorError = new Error ( 'global-error-error' )
10921103 const globalSettledError = new Error ( 'global-settled-error' )
0 commit comments