Is there a way to collect the androix.compose.runt...
# compose
p
Is there a way to collect the androix.compose.runtime.State<T> outside of a Composable? Use case: Unit Tests My ViewModel exposes State<T>, I want to consume it directly from the composable no need for a flow. But now in the test class, I would like to collect the updates to a list of the value history, to make sure the right order. Is it possible outside the composable scope?
p
Ahhh it keeps biting man, yeah this is it. Quick question, is compose State<T> or the snapshotFlow implementation conflated? It seems that I am losing updates that are emitted right after the other.
c
State is always conflated, yes
If you need events, do not use state or state flows
p
Yeah, just read it in the documentation page linked above, sorry I forgot to update. Many thanks
|If you need events, do not use state or state flows I do need State, and in production I don't care if they gets conflated but for testing purposes I want to track the updates history to make sure my logic meets the requirements.
c
You will need to check in between each state update individually
p
Yeup, that's what I am figuring out. Thinking of having 2 instances of the StateUpdater/Reducer function. One for prod and one for testing that adds a delay. Gotta move the function to an injectable interface. It is private to the VM right now
Perhaps instead of a delay I better enque them in a channel
c
I would caution you against doing that. State is conflated intentionally, and writing a test that artificially avoids conflation indicates to me that you are testing the wrong behaviour.
p
🤔 thanks for the advice, let me wonder about a different approach. Perhaps I need to fragment/structure my state representation in a different manner
150 Views