You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Does anyone have an elegant solution to testing out a component that uses staleTime as a prop? I want to run a test that asserts on isStale property in the query cache after the stipulated time provided.
My current approach is:
Mount a wrapper around my component using the ReactQueryCacheProvider. A prop called staleTime is passed in that configures the staleTime in the useQuery hook inside my component.
In my jest test, I use the getQuery to verify the isStale first. Expect it to be false.
Use a setTimeout to check isStale again after an interval of 2000 milliseconds. Use the jest.advanceTimersByTime to move the timer ahead. I expect the isStale value to be true. But it is still false.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Does anyone have an elegant solution to testing out a component that uses
staleTime
as a prop? I want to run a test that asserts onisStale
property in the query cache after the stipulated time provided.My current approach is:
ReactQueryCacheProvider
. A prop calledstaleTime
is passed in that configures thestaleTime
in theuseQuery
hook inside my component.jest
test, I use thegetQuery
to verify theisStale
first. Expect it to befalse
.setTimeout
to checkisStale
again after an interval of 2000 milliseconds. Use thejest.advanceTimersByTime
to move the timer ahead. I expect theisStale
value to betrue
. But it is stillfalse
.What am I missing here?
Beta Was this translation helpful? Give feedback.
All reactions