react-query-firebase
react-query-firebase copied to clipboard
How to write tests on these hooks?
Hi, I have been researching for about a week how to test react query hooks and I couldn't find anything.
I am new to testing and very confused, I have few questions.
- I can see that you have tested these hooks, so do I need to do it myself?
- If I am mocking the api, what exactly am I testing, since the data is not going to be from real database?
- is it common not to write automated for these hooks, since it just works?
Here is a sample code below, how would I write a simple, purposeful working test with jest in this case?
function GetUser() {
const id = "pW5CizOJOpXezr5lGGshDmKdVzZ2";
const ref = doc(firestore, "users", id);
const user = useFirestoreDocument(["users", id], ref);
const name = user.data?.data()?.name;
return (
<div>
{user.isLoading && <div>Loading...</div>}
{name && <p>{name}</p>}
</div>
);
}
export default GetUser;
I am sorry, but I am very confused, so I would appreciate any help so much.
you would test your own hooks like you test the react-query hooks :D Have a look at https://react-query.tanstack.com/guides/testing Does it help?