Skip to content

Instantly share code, notes, and snippets.

@feresr
Last active Nov 12, 2020
Embed
What would you like to do?
// One of the strenghts of MVI is testing!
// 1) I'd love to use the VM API `viewModel.startOnBoarding()` instead of `handleIntents` :(
// 2) Why do we need to `handleIntent` before we can subscribe to the VM, how do I test a sequence of intenets?
@Test
fun `start onBoarding`() {
val testSubscriber = TestSubscriber<Any>() // Why <ANY> we shold be getting states?
viewModel.bind(IdVerificationState(onBoardingCompleted = false))
viewModel.handleIntents(StartOnBoardingInput).subscribe(testSubscriber)
testSubscriber.assertResult(viewModel.RxOutcomes().effect(StartOnBoardingEffect))
}
// What I've seen in most MVI libraries
@Test
fun `start onBoarding`() {
val testSubscriber = TestSubscriber<State>()
//given
viewModel.states(testSubscriber)
//when
viewmodel.offer(SomeIntent)
viewmodel.offer(SomeOtherIntent)
//or
viewmodel.foo()
viewmodel.bar()
//then
testSubscriber.awaitTerminalEvent()
// Assertions
//testSubscriber.assertValueAt()
//testSubscriber.assertValueCount()
}
// 3) OnBoarding Factory (show)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment