How to solve this error? when I run yarn test
I receive this error:
Invariant Violation: Could not find "client" in the context or passed in as an option. Wrap the root component in an , or pass an ApolloClientApolloClient instance in via options.
gql
export const GETLOCATIONNAME = gql`
query FindLocationByAddress($placeSearch: InputEsriGeoCode!) {
findLocationByAddress(placeSearch: $placeSearch) {
name
address {
street1
street2
city
state
zipCode
country
}
geoCode {
longitude
latitude
}
}
}
`;
location.test.js
it('should render location', async () => {
const location = {
request: {
query: GETLOCATIONNAME,
variables: {
placeSearch: {
address: inputString,
},
},
},
result: {
data: {"data":{"findLocationByAddress":[{"name":"Manila, First District NCR, National Capital Region, PHL","address":{"street1":"","street2":"","city":"Manila","state":"National Capital Region","zipCode":"","country":"PHL"},"geoCode":{"longitude":14.604870000000062,"latitude":120.9862700000001}}]}}
},
};
const component = TestRenderer.create(
<MockedProvider mocks={[location]} addTypename={false}>
<LocationSearch name="Manila, First District NCR, National Capital Region, PHL" />
</MockedProvider>,
);
await new Promise(resolve => setTimeout(resolve, 0));
const p = component.root.findByType('p');
expect(p.children.join('')).toContain('Location');
});
resources https://www.apollographql.com/docs/react/development-testing/testing/