-
Notifications
You must be signed in to change notification settings - Fork 786
Using MockedProvider results in error "No more mocked responses for the query: ..." #617
Comments
@tkiethanom As you correctly noted this is likely not an issue with react-apollo but with your code. Make sure the query and variables exactly match. Also note that you need a mock request and response for every time your query is fired. If you refetch the query twice you will need three identical mock requests and responses. If you can't figure it out after a while, I recommend asking for help on the apollo slack or stackoverflow. 🙂 |
@helfer Thanks for the quick response. I found the issue to my problem. I noticed the ID of my variables are getting encoded in the query that's why they don't match. I know Apollo does some ID encoding for deduplication. I believe the |
I was getting this same error and setting the |
@grimunit should I add this prop to
|
@allexysleeps did you get yours working? I'm still getting the error myself after adding removeTypename. |
@stolinski No, we've skipped those tests for now 😞 |
Hey guys i am also getting this :( any updates? I have triple checked my query definitions and it should match. |
Ok i figured it out.. internally there is a line that looks up your responce via the key where the key is the query and the variables.. if your variables are in a different order then the key is different and it all gets fubared. |
Also once you get that working you may need to call |
This is still an issue that applies to MockProvider. I'm opening a new issue since this one has been closed. Here is a commit that can be used to reproduce. |
@scottmcpherson I've found that you need your mocked response, variables and query to all be the exact same data 100%. Chances are if you are getting this you aren't passing the right variable or you aren't returning thee right data in your mocks. Where in your repo are you having this issue, it's a pretty big repo to paw through. |
Yeah, I tripple checked the vars, query, and response, but maybe I'm missing something @stolinski The only thing that I can think of that might be throwing it off is how I'm enveloping my variables with an input variable in the request. And maybe that somehow doesn't match with the response. |
I could be wrong since I just started looking at this, but it looks like you are setting your input value to |
That was it. Thanks @stolinski! I should have just referenced my |
Awesome! Every time I see this error it's because the response and the data aren't the same. It's so easy to do. |
This part of the answer was especially important for me (in my case it is a |
I struggled with this error for way too long. I double checked everything. I though ... Turned out it was a variable that expected an Int but I was sending through as a String. A simple Number(myVariable) fixed it. |
@philberryman it helped me too, variables type wasnt matching. I was sending it an int |
I feel like this is a common issue people run into when trying to create tests using I'd be glad to work on this pull request myself, but I was thinking this error could be more clear by showing a visual "diff" of the mocked responses and the queries that were run, similar to how Jest does it: I've definitely run into errors like @steelx is describing, and it can be hard to compare bigger queries and figure out which parts are different. |
@mattfwood That'd be amazing! |
There is #2883 |
#2883 definitely needs a cleanup and a merge, without a diff it's incredibly hard to tell what the error is. Can we get clarification on what needs to be changed in that PR? (i.e. if lodash/jest-diff/bundle size is still an issue) |
Guys That's awesome.
|
I ran into this issue after adding a const listUploadsMock = {
request: {
query: ListUploads
},
result: {
data: {
numberManagementUploads: uploadsData.numberManagementUploads,
}
}
};
const mountAppWithRouter = (mountPath, mocks = [listUploadsMock]) => {
return (
mount(
<MockedProvider mocks={mocks}>
<App config="/url/create?ajax=1" history={history} />
</MockedProvider>
)
);
};
// rendering my component with an array of 2 identical listUploadsMock fixed it
component = mountAppWithRouter("/new/create_numbers", [listUploadsMock, listUploadsMock]); |
not sure if possible but it would go a loooong way if the mocked response gave some sort of reason into what is not matching. This is a rather painful process and not very well documented |
What does this mean ?
3 identical, I only see ability to add one 'mocks' - are you saying I pass in array of mocks ? Another item that needs documenting. |
Why above are you needing to pass identical mocks in twice ? It's identical. This is a serious code smell imo, a MockedProvider should be given exactly what it needs to have as input and output and pass that through. That is why it's a mock. |
THIS would be awesome. |
I'm not sure why this happens, it seems I need to set up some MockedResponses but I don't know how to do that. When I console.log
_this.mockedResponsesByKey
andkey
inMockNetworkInterface.prototype.query
it looks like the keys don't match because one is a string and the other is an object. I could be reading this wrong though.Steps to Reproduce
Mount a MockedProvider using enzyme.
Buggy Behavior
The component receives
No more mocked responses for the query: ...
inthis.props.data.error
Expected Behavior
Should not throw an error
Version
The text was updated successfully, but these errors were encountered: