Add of turbineOf method #423
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi, I’m Gabriel.
If possible, I would like to propose a function that has helped me validate the strict order of emissions across multiple flows.
While reading the documentation, I found the recommended way to test each flow individually:
turbineScope { val turbine1 = flowOf(1).testIn(backgroundScope) val turbine2 = flowOf(2).testIn(backgroundScope) assertEquals(1, turbine1.awaitItem()) assertEquals(2, turbine2.awaitItem()) }However, with this approach, if I need to validate the strict order of emissions across two flows, such as SharedFlow and StateFlow inside a ViewModel, I only have the option to check them separately.
The problem is that if the production code accidentally changes the order of events, the test still succeeds.
Example (production code):
Test:
But if production code changes to:
The test continues to pass, even though the order is no longer correct.
With this MR, I would like to propose the turbineOf method, which merges multiple flows and allows validating the exact emission order. This function has been very helpful in my own projects, and I believe it would be useful for other developers as well.
Thank you in advance.