-
In the ViewModel, I would like to load data in the init block and update the state flow so that the UI can display it. However, our model layer returns observables and has not been converted to coroutines yet due to certain reasons. The problem is that when I test whether the state flow has the correct data, I noticed that the initial value and the data in onStart are correct, but the data modified in onEach does not appear. Here is an example code:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I'm unsure whether this points to a specific issue in Turbine, or to an issue in your testing setup, which is not something we provide support for as Turbine maintainers. If you can provide a smaller repro that points to a particular bug in Turbine, please share it as an issue. Thank you! |
Beta Was this translation helpful? Give feedback.
Well, you aren't using Turbine wrong or anything. You are using Turbine correctly, but your test setup is failing to plug up
Observable.just(2)
. By the time this line has run,...
myRepository.getData()
has already run.So: not really a question about Turbine, but more a question about "How do I do test setup with coroutines?"
Launching work in
init
is pretty common. If the subject is constructed inside a@Before
, however, then it's not possible to configure any dependencies used by that work: by the time you get to@Test
, the dependencies have already been invoked. So I prefer to avoid using@Before
methods to construct the subj…