Example of a unit test for a component that utilizes useFragment

Hello! I am currently working on introducing data masking and the useFragment hook into one of my projects and I’m realizing that the unit tests for one of the components is no longer passing because of the changes I’ve made. I have searched the docs, the github repo, and done a few google searches, but have yet to come up with any examples that illustrate what a unit test should look like for a component that implements data masking and fragment colocation. Any assistance would be helpful!

Maybe the useFragment tests themselves give you an idea:

Generally:

  • create ApolloClient and InMemoryCache
  • use client.writeFragment to write your fragment or client.writeQuery to write your “root query”
  • render component as you would in a normal test, with a Provider wrapper
1 Like