Are there any examples of unit test that mocks out...
# apollo-kotlin
j
Are there any examples of unit test that mocks out Apollo client?
I see there's a
MockWebServer
....that I think you then use when constructing
ApolloClient
Copy code
serverUrl(mockServer.url())
only small issue right now is I'm using Koin to construct
ApolloClient
and that
url()
looks to be suspend function...
ok, have way around that and looking to mock the json coming back now
(though still running in those issues running for iOS as mentioned in other thread)
@mbonnin In the test right now I'm providing json string as mock response.....should it be possible to use following instead ? https://www.apollographql.com/docs/kotlin/advanced/test-builders/
m
Yep, we're working on improving the ergonomics there (see https://github.com/apollographql/apollo-kotlin/pull/3757) but it should already be possible nevertheless
j
ok, thanks....I'll take a look and see if I can use that instead
👍 1
m
It could be more concise but it's working 🎉
j
nice!
m
I especially like that it sets
__typename
automatically. This is one of the things that I found confusing when creating models by hand
j
yeah, that tripped me up initially when I was trying to create that mock json
💯 1