profile
viewpoint

Ask questionsUpgrading to 3.0.1 gives the following: Invariant violation: Could not find "client"

<!-- Thanks for filing an issue on React Apollo!

Please make sure that you include the following information to ensure that your issue is actionable.

If you don't follow the template, your issue may end up being closed without anyone looking at it carefully, because it is not actionable for us without the information in this template.

PLEASE NOTE: Feature requests and non-bug related discussions are no longer managed in this repo. Feature requests should be opened in https://github.com/apollographql/apollo-feature-requests. -->

Intended outcome:

<!-- What you were trying to accomplish when the bug occurred, and as much code as possible related to the source of the problem. --> All my tests pass when I upgrade to react-apollo 3.0.1 and @apollo/react-testing 3.0.1.

Actual outcome:

I get the following error: Invariant Violation: Could not find "client" in the context or passed in as an option. Wrap the root component in an <ApolloProvider>, or pass an ApolloClient instance in via options

<!-- A description of what actually happened, including a screenshot or copy-paste of any related error messages, logs, or other output that might be related. Places to look for information include your browser console, server console, and network logs. Please avoid non-specific phrases like “didn’t work” or “broke”. -->

How to reproduce the issue:

<!-- If possible, please create a reproduction using https://github.com/apollographql/react-apollo-error-template and link to it here. If you prefer an in-browser way to create reproduction, try: https://codesandbox.io/s/github/apollographql/react-apollo-error-template

Instructions for how the issue can be reproduced by a maintainer or contributor. Be as specific as possible, and only mention what is necessary to reproduce the bug. If possible, try to isolate the exact circumstances in which the bug occurs and avoid speculation over what the cause might be. --> Not quite sure but here's how I have my tests setup:

  <MockedProvider mocks={mocks} addTypename={false}>
    {component}
  </MockedProvider>

Version

<!-- Run the following command in your project directory, and paste its (automatically copied to clipboard) results here:

npx envinfo@latest --preset apollo --clipboard

-->

  System:
    OS: macOS 10.14.5
  Binaries:
    Node: 12.1.0 - /usr/local/bin/node
    Yarn: 1.16.0 - /usr/local/bin/yarn
    npm: 6.9.0 - /usr/local/bin/npm
  Browsers:
    Chrome: 76.0.3809.100
    Safari: 12.1.1
  npmPackages:
    apollo-cache-inmemory: ^1.6.3 => 1.6.3 
    apollo-client: ^2.6.4 => 2.6.4 
    apollo-link: ^1.2.12 => 1.2.12 
    apollo-link-batch-http: ^1.2.12 => 1.2.12 
    apollo-link-context: ^1.0.18 => 1.0.18 
    apollo-link-error: ^1.1.11 => 1.1.11 
    apollo-link-http: ^1.5.15 => 1.5.15 
    apollo-utilities: ^1.3.2 => 1.3.2 
    react-apollo: ^3.0.1 => 3.0.1
apollographql/react-apollo

Answer questions MitchK

I have the same issue. I just got started with apollo testing. Using versions:

    "react-apollo": "^3.0.0",
     ...
    "@apollo/react-testing": "^3.0.1",

This is how I use the MockProvider

        <MockedProvider mocks={mocks} addTypename={false}>
          <MessagesList
            {...props}
          />
        </MockedProvider>

This is the error:

    console.error node_modules/react-test-renderer/cjs/react-test-renderer.development.js:9215
      The above error occurred in the <Query> component:
          in Query (created by MessagesList)
          in RCTSafeAreaView (created by _class)
          in _class (created by SafeAreaView)
          in SafeAreaView (created by MessagesList)
          in MessagesList
          in ApolloProvider (created by MockedProvider)
          in MockedProvider
      
      Consider adding an error boundary to your tree to customize error handling behavior.
      Visit https://fb.me/react-error-boundaries to learn more about error boundaries.

  ● MessageList › snapshot test

    Invariant Violation: Could not find "client" in the context or passed in as an option. Wrap the root component in an <ApolloPro
vider>, or pass an ApolloClient instance in via options.

      at new InvariantError (node_modules/ts-invariant/lib/invariant.esm.js:12:28)
      at invariant (node_modules/ts-invariant/lib/invariant.esm.js:24:15)
      at QueryData.OperationData.refreshClient (node_modules/@apollo/react-hooks/lib/react-hooks.cjs.js:56:115)
      at QueryData.execute (node_modules/@apollo/react-hooks/lib/react-hooks.cjs.js:115:10)
      at node_modules/@apollo/react-hooks/lib/react-hooks.cjs.js:476:55
      at useDeepMemo (node_modules/@apollo/react-hooks/lib/react-hooks.cjs.js:432:14)
      at useBaseQuery (node_modules/@apollo/react-hooks/lib/react-hooks.cjs.js:475:16)
      at useQuery (node_modules/@apollo/react-hooks/lib/react-hooks.cjs.js:492:10)
      at Query (node_modules/@apollo/react-components/lib/react-components.cjs.js:26:41)
      at renderWithHooks (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:5036:18)
useful!
source:https://uonfu.com/
answerer
Michael Kunzmann MitchK SAP Palo Alto, CA (USA) Associate Development Architect @ SAP Innovation Center - Cloud Engineering
Github User Rank List