Hi is there a way to mock the properties of a sing...
# mockk
t
Hi is there a way to mock the properties of a singleton? For example given:
Copy code
object Singleton {
  val client = SomeClient()
   fun foo() {
    // calls to me are mocked in my unit test
    client.bar()
  }
}
When I mock calls to
foo
with
mockkObject
using
every
the SomeClient() constructor is still called. So do I also need to mock SomeClient, or is there a way I can mockkAll of Singleton or perhaps just intercept calls to client?
m
i think you can do this by mocking the constructor for
SomeClient
, doing something like
Copy code
every { anyConstructed<SomeClient>().bar() }
does this make sense to you?
t
Ya i think so ... and if SomeClient were to also be a singleton? 😂
I guess i'll need to find the concrete class in the dependency graph and mock it there 🤔