You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I can correctly verify the state transitions in the unit test, but I am not able to verify functions called in response to onEach subscription. I looked through the documentation and could not find something that could help. Is there a way to achieve this?
example:
class SomeViewModel(initialState: SomeState, tracker: Tracker): MavericksViewModel<SomeState>(initialState) {
init {
onEach(SomeState::propertyA) {
tracker.fireAnalyticsEvent() // Want to verify this function gets called on state changes
}
}
}
class SomeViewModelTest {
@get:Rule
val mvrxTestRule = MvRxTestRule(testDispatcher = UnconfinedTestDispatcher())
@Test
fun sampleTest() {
// given
sut = SomeViewModel(SomeState(a, b, c), MockTracker())
// when
sut.doSomething()
// then
withState(sut) { state ->
assertTrue(state.propertyA == a1) // This works
}
verify(1) {
// Verify this function was called once
tracker.fireAnalyticsEvent() // This fails
}
}
}
PS: Thank you for this amazing library, it is a delight to use.
The text was updated successfully, but these errors were encountered:
Hi, sorry for the late answer, but if anyone is interested, verify(1) is wrong, because you're setting propertyA twice. First when you set the initial state, then when you call doSomething. The rest works fine for me:
I am trying to unit test certain flows on the viewmodel which are triggered
onEach
subscription of the a specific property. https://airbnb.io/mavericks/#/core-concepts?id=subscribing-to-state-changesI can correctly verify the state transitions in the unit test, but I am not able to verify functions called in response to
onEach
subscription. I looked through the documentation and could not find something that could help. Is there a way to achieve this?example:
PS: Thank you for this amazing library, it is a delight to use.
The text was updated successfully, but these errors were encountered: