apollo-client: Using MockedProvider for tests, ... gql fragments not working
Issue Description
I’m trying to use the MockedProvider component in Jest (v29.5.0) tests. Some time ago, we changed the data model for one of our queries, resulting in the following structure for our query mock:
...
result: {
data: {
todaysWorkout: {
id: 'mockWorkout',
slots: {
slot1: {...},
slot2: {...},
slot3: {...},
slot4: {...},
slot5: {...},
},
},
},
},
The data the comes through to our component query in tests loses all of the slot
entries in the slots
object, resulting in data
being the following:
{
todaysWorkout: {
id: 'mockWorkout',
slots: {},
},
}
If I change slots
in the mock to seemingly ANY OTHER WORD, such as slotss
(with two final s
) or abracadabra
or bobsYourUncle
, the data comes through correctly, and we get all of our slot
entries (slot1
, slot2
, …).
Is slots
a reserved word or something?
Link to Reproduction
Nope
Reproduction Steps
No response
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 26 (13 by maintainers)
You’re welcome!
As for suggestions, not sure I can give any good specific advice without seeing the entirety of a test. You’re always welcome to check out how we test
useQuery
internally if that may give you some clues as to how to structure some of your tests, though granted this isn’t a full application so we have a lot of dummy queries/data in there 😄.I’ll go ahead and close out this issue, but feel free to ping us if you need anything more!
I don’t think that this has ever worked with this query as is. At some point, maybe a year ago, our graph changed, and as a result our query changed. I recently upgraded jest, and this upgrade revealed warnings around our mocks that we previously weren’t seeing, meaning that we didn’t know that the mocks weren’t working as expected. I’m trying to resolve this, but unfortunately my colleagues who worked on this last year are no longer with our team.
I downgraded all the way to v3.0.2, and saw no difference in behavior.