https://kotlinlang.org logo
Title
j

John O'Reilly

12/29/2021, 12:09 PM
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
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

mbonnin

12/30/2021, 10:41 PM
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

John O'Reilly

12/30/2021, 10:43 PM
ok, thanks....I'll take a look and see if I can use that instead
👍 1
m

mbonnin

12/30/2021, 10:55 PM
It could be more concise but it's working 🎉
j

John O'Reilly

12/30/2021, 11:11 PM
nice!
m

mbonnin

12/30/2021, 11:14 PM
I especially like that it sets
__typename
automatically. This is one of the things that I found confusing when creating models by hand
j

John O'Reilly

12/30/2021, 11:15 PM
yeah, that tripped me up initially when I was trying to create that mock json
💯 1