Last active
July 23, 2023 14:31
-
-
Save Foxpace/b27ef8eeec09f3dbe4d8e4a02c47de3f to your computer and use it in GitHub Desktop.
Test with Turbine and multiple steps
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
@Test | |
fun `Given the ViewModel waits - When the event OnLaunch comes, then both computations runs successfully`() = | |
runTest { | |
turbineScope { | |
// ARRANGE | |
val expectedString = "Result" | |
heavyComputation.stub { | |
onBlocking { doComputation() } doAnswer { expectedString } | |
} | |
val sut = ExampleViewModel(heavyComputation) | |
val firstStateReceiver = sut.vmState.testIn(backgroundScope) | |
val secondStateReceiver = sut.secondVmState.testIn(backgroundScope) | |
// ACTION | |
sut.onEvent(VmEvents.OnLaunch) | |
// CHECK | |
assertEquals(VmState.Waiting, firstStateReceiver.awaitItem()) | |
assertEquals(VmState.Waiting, secondStateReceiver.awaitItem()) | |
assertEquals(VmState.Running, firstStateReceiver.awaitItem()) | |
assertEquals(VmState.Running, secondStateReceiver.awaitItem()) | |
assertEquals(VmState.Finished(expectedString), firstStateReceiver.awaitItem()) | |
assertEquals(VmState.Finished(expectedString), secondStateReceiver.awaitItem()) | |
assertEquals(VmState.Waiting, firstStateReceiver.awaitItem()) | |
assertEquals(VmState.Waiting, secondStateReceiver.awaitItem()) | |
firstStateReceiver.cancel() | |
secondStateReceiver.cancel() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment