Created
October 9, 2019 09:00
-
-
Save manuelvicnt/6807564f0b3e684512aa844d2fc0562c to your computer and use it in GitHub Desktop.
Plaid - ShowViewModelTest solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ShotViewModelTest { | |
// This CoroutineDispatcher is injected in the ViewModel and use case | |
private val testCoroutineDispatcher = TestCoroutineDispatcher() | |
@After | |
fun tearDown() { | |
testCoroutineDispatcher.cleanupTestCoroutines() | |
} | |
@Test | |
fun loadShot_emitsTwoUiModels() = testCoroutineDispatcher.runBlockingTest { | |
// 1) Given coroutines have not started yet and the View Model is created | |
testCoroutineDispatcher.pauseDispatcher() | |
val viewModel = ... // Creates viewModel injecting testCoroutineDispatcher | |
// Then the fast result has been emitted | |
val fastResult = viewModel.shotUiModel.getOrAwaitValue() | |
assertTrue(fastResult.formattedDescription.isEmpty()) | |
// 2) When the coroutine starts | |
testCoroutineDispatcher.resumeDispatcher() | |
// 3) Then the slow result has been emitted | |
val slowResult = viewModel.shotUiModel.getOrAwaitValue() | |
assertTrue(slowResult.formattedDescription.isNotEmpty()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment