-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MockedProvider not returning data when @client is specified #4532
Comments
Thanks @nicoladj77 - let's keep this as its own issue for now, but I'll be addressing this and #4325 at the same time. |
Is there any ETA on this? I am relying on Don't want to put you in a hurry, I just want to know if I have to think about some alternative strategy for testing instead of waiting for a fix. |
Hi @hwillson , @simonedavico - Any updates on this? Running into same problem as above. |
+1 |
+1 |
This seems related to #4520 |
Hey everyone. I'm running into the same issues here. I've gotten around this by not including the custom resolvers (which makes the test suite noisy with the apollo warning about client directives without resolvers, but hey) in the MockedProvider in conjunction with using the const mocks = createMocks([{ isConnected: false, isPluggedIn: true }]);
const { container, getByText } = render({}, mocks);
await wait(() => {
expect(toJSON(container)).toMatchSnapshot();
}); Where the |
+1 |
yeah same for me removing the resolvers from the mockProvider it works. Also make sure if you have __typename in the mocks.
|
I'm also getting this. Do you think this bug will be fixed? Or should i be testing local apollo things differently? |
I'm still facing this issue too. |
Bump, 1.5 years later after the original poster! Facing the same issue... |
Please note that const {
mocks,
addTypename,
defaultOptions,
cache,
resolvers,
link
} = this.props;
const client = new ApolloClient({
cache: cache || new Cache({ addTypename }),
defaultOptions,
link: link || new MockLink(
mocks || [],
addTypename,
),
resolvers,
}); This means that if you're using Apollo Client 2.x local resolvers, or Apollo Client 3.x type/field policies, you have to tell the If using Apollo Client 2.x local resolvers, make sure your <MockedProvider mocks={mocks} resolvers={resolvers} ... If using Apollo Client 3.x type/field policies, make sure your configured <MockedProvider mocks={mocks} cache={cache} ... |
For my scenario, i'm not testing a mutation or any update to the local state. The component i'm testing just simply fetches some data from local state. I'm not following how passing in local resolvers would help here. Can you provide an example here? |
@chris-mo The mocked data you pass into |
@hwillson thanks! I actually gave this a shot last night, which got rid of the error message mentioned above, but i must have some incorrect syntax as the data returned still returns as let's say i have the following query The resolver i have for this but seems incorrect is
EDIT: I got it to work, just had to edit my return obj. Thanks for the response @hwillson |
@hwillson Thanks for the detailed explanation! That helped me better understand what's going on under the hood. Unfortunately I'm still experiencing this issue. I have a query labeled with @client, which I am using in my React component, as well as in the the mock Do you have any ideas of what I should look for? FWIW I'm on |
closing this issue as we did some documentation updates to account for local state testing. in #9867 |
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:
My query:
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 inresult.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
The text was updated successfully, but these errors were encountered: