Stubbing a method on a spyk object calls the original method immediately

Viewed 822

for example the method

   class SomeClass() {
       fun login(listener: (Boolean) -> Unit ) {
            do some async logic and then call the listener with the result
      }
   }

   val spy = spyk(SomeClass())  {

          val completion = slot<(Boolean) -> Unit>()
         //this immediately calls the original login method
         every { login(capture(completion)) } answers {
              completion.captured.invoke(true)
         }
     }

trying to stub the login method immediately invokes it.

Do you know how to just stub it and not invoke it?

1 Answers
Related