Hey pact-js, any tips for working with the `Mocked...
# pact-js
j
Hey pact-js, any tips for working with the
MockedProvider
apollo client component for writing consumer tests? I see in the example that there is an
ApolloClient
defined, but for my use case, I'm writing these tests in a separate package that doesn't instantiate an
ApolloClient
anywhere; all the unit tests for this interface look kinda like this (using react testing library):
Copy code
render(
    <MockedProvider mocks={mocks} addTypename={false}>
      <TestComponent />
    </MockedProvider>
  );
  const results = screen.getByText(/queryResults/i);
  expect(results).toHaveTextContent('true');
where the actual request I want to write a contract for is being done inside of
TestComponent
when it's rendered in the context of
MockedProvider
. It would be nice if the
MockedProvider
api had a url prop, but it doesn't. Is there a clean way to render this test component in the context of the pact mock server? Or do I need to instantiate my own custom
ApolloClient
and pass it the mock server url, even though this isn't exactly how the underlying app code works?
Actually if I can pull the api method out of the component this shouldn't be an issue
☝️ 1
m
Yep, that would be my recommendation. I wouldn’t normally recommend testing the component + the API logic at the same time (at least not at this level).