File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
packages/query-core/src/__tests__ Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -1171,4 +1171,30 @@ describe('mutations', () => {
11711171 expect ( unhandledRejectionFn ) . toHaveBeenNthCalledWith ( 4 , newSettledError )
11721172 } )
11731173 } )
1174+
1175+ test ( 'should not remove mutation when one observer is removed but another still exists' , async ( ) => {
1176+ const observer1 = new MutationObserver ( queryClient , {
1177+ gcTime : 10 ,
1178+ mutationFn : ( ) => sleep ( 10 ) . then ( ( ) => 'data' ) ,
1179+ } )
1180+ const unsubscribe1 = observer1 . subscribe ( ( ) => undefined )
1181+
1182+ observer1 . mutate ( )
1183+ await vi . advanceTimersByTimeAsync ( 10 )
1184+
1185+ expect ( queryClient . getMutationCache ( ) . getAll ( ) ) . toHaveLength ( 1 )
1186+
1187+ const mutation = queryClient . getMutationCache ( ) . getAll ( ) [ 0 ] !
1188+ const observer2 = new MutationObserver ( queryClient , {
1189+ gcTime : 10 ,
1190+ mutationFn : ( ) => sleep ( 10 ) . then ( ( ) => 'data' ) ,
1191+ } )
1192+ mutation . addObserver ( observer2 )
1193+
1194+ unsubscribe1 ( )
1195+
1196+ await vi . advanceTimersByTimeAsync ( 10 )
1197+
1198+ expect ( queryClient . getMutationCache ( ) . getAll ( ) ) . toHaveLength ( 1 )
1199+ } )
11741200} )
You can’t perform that action at this time.
0 commit comments