How to create an instance of SkieSwiftStateFlow in Swift for testing #54
-
We are receiving a SkieSwiftStateFlow from our shared library. For unit testing we need to create a SkieSwiftFlow to mock different values we receive from the flow. final class ViewModelMocked: ViewModel {
var uiState: SharedLibary.SkieSwiftStateFlow<UiState>
init() {
uiState = // How to create a SkieSwiftStateFlow?
}
} We found no way of creating a SkieSwiftStateFlow with a value. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi! There are multiple options. The easiest one is to write a function in Kotlin that will return a regular Kotlin flow with the behavior you need and just call it from Swift. (and let SKIE convert the Flow to the required SkieSwiftFlow). You can also use Flow builders from Coroutines (for example: Last option: If you have some way of constructing regular Coroutines Flow in Swift, you can use conversion constructors provided by SKIE: |
Beta Was this translation helpful? Give feedback.
Hi!
There are multiple options. The easiest one is to write a function in Kotlin that will return a regular Kotlin flow with the behavior you need and just call it from Swift. (and let SKIE convert the Flow to the required SkieSwiftFlow).
You can also use Flow builders from Coroutines (for example:
emptyFlow
,flowOf
, etc.). However, that would require you to export the entire Coroutines library to Swift, which I wouldn't recommend. But you can write simple wrapping functions for those builders to workaround this problem.Last option: If you have some way of constructing regular Coroutines Flow in Swift, you can use conversion constructors provided by SKIE:
SkieSwiftFlow(SkieKotlinFlow< Ui…