File tree Expand file tree Collapse file tree
packages/query-devtools/src/__tests__ Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1146,6 +1146,39 @@ describe('Utils tests', () => {
11461146 }
11471147 } )
11481148
1149+ it ( 'should place a stale query after a fresh one when both are idle and have observers' , ( ) => {
1150+ const staleObserver = new QueryObserver ( queryClient , {
1151+ queryKey : [ 'stale' ] ,
1152+ staleTime : 0 ,
1153+ } )
1154+ const staleUnsubscribe = staleObserver . subscribe ( ( ) => { } )
1155+ const stale = queryClient
1156+ . getQueryCache ( )
1157+ . find ( { queryKey : [ 'stale' ] } ) !
1158+ stale . setState ( {
1159+ ...stale . state ,
1160+ fetchStatus : 'idle' ,
1161+ data : 'data' ,
1162+ dataUpdatedAt : 200 ,
1163+ } )
1164+
1165+ const fresh = buildQuery ( [ 'fresh' ] , {
1166+ fetchStatus : 'idle' ,
1167+ data : 'fresh-data' ,
1168+ dataUpdatedAt : 100 ,
1169+ } )
1170+ const freshUnsubscribe = addObserver ( fresh )
1171+
1172+ try {
1173+ expect ( stale . isStale ( ) ) . toBe ( true )
1174+ expect ( statusSort ( fresh , stale ) ) . toBe ( - 1 )
1175+ expect ( statusSort ( stale , fresh ) ) . toBe ( 1 )
1176+ } finally {
1177+ staleUnsubscribe ( )
1178+ freshUnsubscribe ( )
1179+ }
1180+ } )
1181+
11491182 it ( 'should fall back to "last updated" sort within the same status rank' , ( ) => {
11501183 const older = buildQuery ( [ 'older' ] , { dataUpdatedAt : 100 } )
11511184 const newer = buildQuery ( [ 'newer' ] , { dataUpdatedAt : 200 } )
You can’t perform that action at this time.
0 commit comments