Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Commit

Permalink
Merge pull request #2825 from apollographql/hwillson/allow-mocked-res…
Browse files Browse the repository at this point in the history
…olvers

Allow resolvers to be passed into `MockedProvider` and set a default
  • Loading branch information
hwillson authored Feb 27, 2019
2 parents 7801b79 + f1b1103 commit e4a5b68
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
10 changes: 10 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Change log

## 2.5.1

### Bug Fixes

- Make sure `MockedProvider` enables Apollo Client 2.5's local state handling,
and allow custom / mocked resolvers to be passed in as props, and used with
the created test `ApolloClient` instance. <br/>
[@hwillson](https://github.com/hwillson) in [#2825](https://github.com/apollographql/react-apollo/pull/2825)


## 2.5.0

### Improvements
Expand Down
12 changes: 10 additions & 2 deletions src/test-utils.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import ApolloClient from 'apollo-client';
import { DefaultOptions } from 'apollo-client';
import { DefaultOptions, Resolvers } from 'apollo-client';
import { InMemoryCache as Cache } from 'apollo-cache-inmemory';

import { ApolloProvider } from './index';
Expand All @@ -13,6 +13,7 @@ export interface MockedProviderProps<TSerializedCache = {}> {
addTypename?: boolean;
defaultOptions?: DefaultOptions;
cache?: ApolloCache<TSerializedCache>;
resolvers?: Resolvers;
}

export interface MockedProviderState {
Expand All @@ -27,11 +28,18 @@ export class MockedProvider extends React.Component<MockedProviderProps, MockedP
constructor(props: MockedProviderProps) {
super(props);

const { mocks, addTypename, defaultOptions, cache } = this.props;
const {
mocks,
addTypename,
defaultOptions,
cache,
resolvers = {},
} = this.props;
const client = new ApolloClient({
cache: cache || new Cache({ addTypename }),
defaultOptions,
link: new MockLink(mocks || [], addTypename),
resolvers,
});

this.state = { client };
Expand Down

0 comments on commit e4a5b68

Please sign in to comment.