Hello everyone, i'm writing unit tests in my VM us...
# android
l
Hello everyone, i'm writing unit tests in my VM using a mockk and Turbine combination but i'm facing an interesting problem in this test:
Copy code
@Test
fun `Should show api error when create request token fails`() = runTest {
    every { loginRepository.createRequestToken() } returns flow {
        emit(
            Source.Error(
                NetworkError(400, "error")
            )
        )
    }

    viewModel.events.test {

        viewModel.onLoginClick()

        verify(exactly = 1) { loginRepository.createRequestToken() }
        confirmVerified(loginRepository)

        Truth.assertThat(viewModel.isButtonLoading.value).isFalse()

        Truth.assertThat(awaitItem())
            .isInstanceOf(LoginEvents.ShowApiError::class.java)

        cancelAndConsumeRemainingEvents()
    }
}
When i run this test the Truth assert that verifies the event succeeds, but mockk throws an error saying that repository,createRequestToken() wans't called
I'm my viewModel this event is emitted only when the response of loginRepository.createRequestTokens() returns an error, so theoretically it isn't possible to emit this event without calling the repository
p
Please post your ViewModel, it's impossible to tell what's going on