Lucca Beurmann
01/11/2022, 5:52 PM@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 calledLucca Beurmann
01/11/2022, 5:53 PMPaul Woitaschek
01/11/2022, 9:43 PM