2 years ago

#75084

test-img

Abhinav Gaurav

MockedProvider is not providing response once using custom apollo client

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(
        <MockedProvider mocks={mocks} addTypename={false}>
          <DeviceTenantMapTable {...defaultProps} />
        </MockedProvider>
      );
    });
    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.

reactjs

react-apollo

0 Answers

Your Answer

Accepted video resources