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.

Mocking graphqlLodash with Jest

See original GitHub issue

Hello,

First of all, thanks for the nice project. I am trying to mock graphql-lodash with Jest, in order to test components decorated with it. Is there any de-facto / preferred way of mocking it? Below I add my code snippets.

Tests:

import React from 'react';
import chai, { expect } from 'chai';
import { shallow } from 'enzyme';
import chaiEnzyme from 'chai-enzyme';

import Foo from './Foo';

describe('Foo', () => {
  const shallowed = shallow(<Foo />);

  it('test Foo', () => {
   {...}
  });
});

chai.use(chaiEnzyme());

I have tried multiple ways to mock, but i keep on getting errors.

Thanks 🙂

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
IvanGoncharovcommented, Oct 18, 2017

@aperkaz Thanks for example 🎉

0reactions
aperkazcommented, Oct 17, 2017

@IvanGoncharov right now we are using it to transform the results of graphQL queries to a CMS (Contentful) to the right props that our React components require. Using graphql-lodash allows to easily change the props to what the stateless components are expecting, and also easy to extend if the props in components are chagned/renamed. Below I attach an example query:

query getPost($id: ID!) {
  post(id: $id) {
    photo: postPhoto {
      alt: title
      src: url
    }
    headline
    subtitle: postPerex
    content
    author: postAuthor @_(get: "name") {
      name
    }
    date
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Mocking graphqlLodash with Jest · Issue #8 · IvanGoncharov ...
I am trying to mock graphql-lodash with Jest, in order to test components decorated with it. Is there any de-facto / preferred way...
Read more >
Mock GraphQL and REST in Storybook and Jest with MSW
Walk through how to mock GraphQL or REST responses at network level, and share mocks between Storybook and Jest tests…
Read more >
React-apollo mock provider return no data - Help
i have a component which uses react-apollo graphql function to query data. i am trying to retrieve mock apollo provider using mocked ......
Read more >
Mocking | Guide - Vitest
More #. Jest's Mock Functions ... It will let you mock both REST and GraphQL network requests, and is framework agnostic.
Read more >
Mocking a lodash function with Jest - Today I Learned
Jest is a framework for testing JavaScript. In this, we will do a quick dive into how to mock a function from a...
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