Want to test loading
state of useQuery
.
#1178
-
What is the preferred way to test the loading state of a Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Do you mean like in a unit test? Assuming you've mocked your actual API call method, you can define the mock implementation to have a delay before it resolves and use this to check the loading state. If you are using jest (or something with a similar API) the |
Beta Was this translation helpful? Give feedback.
-
have a look at how react-query tests the Yes, you will need to mock your actual api call somehow (jest, mock-service-worker, ...) |
Beta Was this translation helpful? Give feedback.
Do you mean like in a unit test? Assuming you've mocked your actual API call method, you can define the mock implementation to have a delay before it resolves and use this to check the loading state. If you are using jest (or something with a similar API) the
useFakeTimers
method will be useful here to manually advance your time so you don't run into race conditions.