So we’ve been using MockedProvider for testing for some time now and recently found the docs saying
Unless you explicitly configure your mocks to expect a
__typename
field, always setaddTypename
tofalse
in your tests.
We were okay with changing our mocks and thus removed __typename
from them. What I noticed is that our tests that check if the correct data was being passed to some component started failing. We use the concept of colocated fragments and thus our code is organized as follows:
Parent.tsx
const Parent = () => {
const { data: data, loading: loading } = useQuery(Parent.query);
// lot of stuff here
<Child data={data} />
}
Parent.query = gql(`
query sampleQuery() {
query {
id
...Child_SubData
}
}
`)
Child.tsx
const Child = (data: FragmentType<typeof Child_SubDataFragmentDoc>) => {
// some stuff here
}
Child.fragment = gql(`
fragment Child_SubData on SubData {
id
name
blah
}
`)
The test that fails is the one that checks if correct data has been passed to Child component. With addTypename={false}
, the received data only has id
field and name
and blah
have disappeared.
Is this a bug, or should we restructure our tests somehow? We also use caching, and our graphql schema on server frequently changes (we keep that synced through graphql-codegen), so are there any downsides to removing __typename
from the mocks for these kinds of tests?
Thank you in advance.