benawad / apollo-mocked-provider

Automatically mock GraphQL data with a mocked ApolloProvider
MIT License
92 stars 25 forks source link

How to mock Types? #13

Open nealoke opened 5 years ago

nealoke commented 5 years ago

As the title says, how can I mock a type such as DateTime? 😄

const MockedNavBarSubscriber = ({ mockResponse, ...props }) => (
    <ApolloMockedProvider
        customResolvers={{
            DateTime: () => new Date(),
            Query: () => ({ me: () => mockResponse.me, company: () => mockResponse.company })
        }}
    >
        <NavBarSubscriber {...props} />
    </ApolloMockedProvider>
);

image

benawad commented 5 years ago

I'm not sure

baleeds commented 5 years ago

@nealoke you figure this out? I'm hitting the same issue

nealoke commented 5 years ago

@baleeds no, I've disabled my test and will look into this again later 😢

JaKXz commented 4 years ago

Using React testing library and the latest apollo-mocked-provider (at time of writing), we got it to work with:

  <ApolloMockedProvider
    customResolvers={{
      Date: () => jest.fn(() => new Date()),
      Query: () => ({ ... }),
      Mutation: () => ({ ... }),
    }}
  />