hasura / hasura/graphql-engine
MockedProvider is not providing response once using custom apollo client
- Dominant language
- TypeScript
- Stars
- 32.1k
- Forks
- 3k
- PR merge metrics
- PR metrics pending
Description
We want to test the below code, where we have our custom apollo client and this custom apollo client uses WebSocket link. When we run the test file given below, onCompleted callback in the query does not get called.
```
const { loading, error, data, refetch } = useQuery(
GET_DOG_QUERY,
{
variables: { nameOne },
client: apolloClient,
fetchPolicy: "network-only",
onCompleted: data => {
console.log("Abhinav123456789");
}
}
);
```
Below is the mocked request and response:
```
const mocks = [
{
request: {
query: GET_DOG_QUERY,
variables: {
nameOne: 'Buck',
},
},
result: () => {
return {
data: {
dog: { id: '1', name: 'Buck', breed: 'bulldog' },
}
}
}
}
];
```
Below is the test case we are trying to verify
```
test("find loader", async () => {
await act(async () => {
wrapper = mount(
);
});
await act(async () => {
await new Promise((resolve) => setTimeout(resolve, 0));
});
wrapper.upadate();
expect(wrapper.find('[data-test="table customer-data-table"]').prop("isLoading")).toBe(true);
});
```
Please tell us how to proceed with the test with our custom Apollo client component.
Contributor guide
Research direction
Start by reproducing the provided test using MockedProvider, GET_DOG_QUERY, and the custom Apollo client passed to useQuery. Compare the mocked request with the custom client's behavior, then verify that onCompleted is called and the loading assertion reflects the intended result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, react, typescript
- Domain
- frontend, testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100