question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MockedProvider not returning data when @client is specified

See original GitHub issue

I didn’t know if I should open a new issue or if I should have commented on #4325

Intended outcome: Writing a MockedProvider for a query only with @client directives should return data

Actual outcome: No data is returned when the test is run.

How to reproduce the issue: My test:

const mockLocal = () => [
  {
    request: {
      query: GET_STATE,
      variables: {},
    },
    result: {
      data: {
        renderType: 'default',
        path: '',
        staticContent: {
          navigation: {
            links: [
              {to: '/article', text: 'Article'},
              {to: '/home', text: 'Home'}
            ]
          },
          header: {
            logo: ''
          }
        }
      }
    },
  },
];

describe('<Html>', () => {
  it('renders correctly', async () => {
    const tree = renderer
    .create(<MockedProvider mocks={mockLocal()} addTypename={false}><Router><Navigation/></Router></MockedProvider>)
    .toJSON();
    await wait(0);
    expect(tree).toMatchSnapshot();
  });
});

My query:

export const GET_STATE = gql`
  {
    renderType @client,
    path @client,
    staticContent @client {
      navigation @client {
        links @client {
          to,
          text
        }
      }
     header @client {
        logo
      }
    }
  }
`;

The issue is that when I run the mock, and I console.log in the component that uses the query, the result is an empty object instead of what I specified in result.data

Versions System: OS: Windows 10 Binaries: Node: 11.4.0 - C:\Program Files\nodejs\node.EXE Yarn: 1.13.0 - C:\Program Files (x86)\Yarn\bin\yarn.CMD npm: 6.4.1 - C:\Program Files\nodejs\npm.CMD Browsers: Edge: 42.17134.1.0 npmPackages: apollo-client: ^2.5.1 => 2.5.1 react-apollo: ^2.5.1 => 2.5.1

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:7
  • Comments:18 (4 by maintainers)

github_iconTop GitHub Comments

8reactions
axelnormandcommented, Jan 5, 2020

I’m also getting this. Removing the resolvers being added to MockedProvider makes the mocked queries work. However i get the annoying “Found @client directives in a query but no ApolloClient resolvers were specified.” console warning. Furthermore I wonder how to best to test components that use local mutations resolvers if they’re not being added?

Do you think this bug will be fixed? Or should i be testing local apollo things differently? Thanks

6reactions
mocantimoteidavidcommented, Mar 6, 2020

I’m still facing this issue too. Maybe we could do it with the temporary workaround for now, but wanted to ask the same question - if any attention is being paid to this issue, or if anything new came up about it. If it helps, I could also provide my case, but it’s really not that different compared to what is already discussed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Apollo MockedProvider not returning expected data
I simplified your hook implementation and put together a working example: import { useQuery, gql } from "@apollo/client"; export const ...
Read more >
How to fix Apollo's MockedProvider returning empty objects for ...
When your query asks for optional fields, but the response does not provide them, it fails silently, and you get an empty response....
Read more >
React-apollo mock provider return no data - Help
i am trying to retrieve mock apollo provider using mocked provider from react-apollo/test-utils. mocked data is not coming in the mocked ...
Read more >
Debugging Apollo GraphQL MockedProvider - Swarmia
It's not easy to debug why a test case failed if the issue ... if the MockedProvider doesn't find a matching mock for...
Read more >
Testing React components - Apollo GraphQL - w3resource
</p>; return ( <p> {data.dog.name} is a {data.dog.breed} </p> ); }. Given ... Apollo Client in the context it('should render without error', ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found