react-query-firebase icon indicating copy to clipboard operation
react-query-firebase copied to clipboard

How to write tests on these hooks?

Open Juilli opened this issue 4 years ago • 1 comments

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.

  1. I can see that you have tested these hooks, so do I need to do it myself?
  2. If I am mocking the api, what exactly am I testing, since the data is not going to be from real database?
  3. 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.

Juilli avatar Dec 11 '21 23:12 Juilli

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?

ZeroPie avatar Jan 08 '22 18:01 ZeroPie