Improve GraphQL local resolver tests
@mlunoe I've taken the time to build a small reproduction for the test and it seems
result
hook is triggered successfully. The only thing we need to do is to populate mocked client cache correctly (if we don't have correct data in the cache, the query is not triggered).(when running the test, you would see plenty of console logs triggered in local query
result
hook)Thank you @ntepluhina! I have updated the test to use that method. However, I still found a few issues with this approach:
- When the app calls
fetchMore
in the app it seems to not have the query registered for that. I’ve read on some forums that it could be something with variables, but registering variables for the query did not solve the problem (or perhaps I did not use the correct approach?)- The result returned from the API (using
mockAdapter
) does not seem to enter the component when I also callwriteQuery
- I know thatwriteQuery
is a replacement for usingmockAdapter
, but using it makes it hard to fake errors from failed queries.
Source: !46601 (comment 447066257)
The above test mocks the fetchMore
implementation in the component to test successes and errors from the API. However, mocking that implementation is a code smell and should not be necessary for local resolvers as we have mockAdapter
. But using writeQuery
disables the local resolvers and therefore removes the possibility for using mockAdapter
to mock network responses.
MR in question: !46601 (merged)