Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jest testing apollo provider getting error : TypeError: this.client.watchQuery is not a function

I was getting error : Invariant Violation: Could not find "client" in the context of Query or as passed props. Wrap the root component in an

then I wrapped component in apollo provider with prop client while testing.


TypeError: this.client.watchQuery is not a function

  732 |
  733 |   it('should close the overlay when the close button is clicked', () => {
> 734 |     const mandateBatchWrapper = mount(
  735 |       <ApolloProvider client={clientForApollo}>
  736 |         <MandateBatch
  737 |           data={data}

like image 738
sonal Avatar asked May 12 '18 11:05

sonal


1 Answers

Your ApolloClient might be mocked. If you have a file __mocks__/apollo-client.js somewhere, ApolloClient will be mocked even without calling jest.mock('apollo-client'). https://jestjs.io/docs/en/manual-mocks#mocking-node-modules.

like image 155
ti6on Avatar answered Nov 13 '22 09:11

ti6on