Replies: 1 comment
-
This seems like more of a coroutine testing issue and not something specific to molecule. By calling The way we handle this is to use channels which allows the test to suspend and wait for the event handler to execute. Not sure how to hook this up using class TestRandomService : RandomService {
val sideEffects = Channel<Unit>(capacity = UNLIMITED)
override fun sideEffect() {
sideEffect.trySend(Unit)
}
} And then your test would be updated to something like: @Test fun sideEffect() {
val events = MutableSharedFlow<CounterEvent>()
val service = TestRandomService()
testMolecule({
CounterPresenter(events, service)
}) {
assertEquals(CounterModel(0, false), awaitItem())
events.emit(SideEffect)
withTimeout(1.seconds) {
service.sideEffects.receive()
}
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm having trouble determining how I might test side effects of the presenter. Using the project sample as an example:
Since there is no recomposition when emitting a
SideEffect
event, I can't assert that the service was actually invoked (FYI, I'm using mockk in my tests for this):If the presenter were to also update the
CounterModel
in some way when receiving aSideEffect
event, then the above test would pass.Is there a way to test such scenarios? Or am I approaching the test and/or the presenter wrong?
Beta Was this translation helpful? Give feedback.
All reactions