TanStackT
TanStack2y ago
3 replies
urgent-maroon

testing a query cache

Hey guys, I'm using a query with a stale time (I mean the cache is activated) and in my test I would like to check that the data from the cache is well retrieved. I have access to my queryClient in my test but I don't know what to use to get this assertion.

For exemple I have my keys: ['tests', 1] and ['tests', 2]
I start with ['tests', 1] and I expect the queryFn to be called
then I swap to ['tests', 2] and I expect the queryFn to be called
to finish I swap back to ['tests', 1] and expect get the data from the cache <-- that's what I need

do you have any ideas?
Was this page helpful?