Mini
02/08/2022, 7:12 PMMini
02/08/2022, 7:12 PMclass MyTest() : FunSpec({
val dispatcher = TestCoroutineDispatcher()
listeners(MainCoroutineListener(dispatcher), MtLogListener())
class MyViewModel : ViewModel(){
val x = MutableStateFlow(5)
val y = MutableStateFlow(2)
val doubleX = x.map {
it * 2
}.stateIn(
viewModelScope,
SharingStarted.Eagerly,
null
)
val combinedFlow = x.combine(y){ xValue, yValue ->
xValue * yValue
}.stateIn(
viewModelScope,
SharingStarted.Eagerly,
null
)
}
val viewModel = MyViewModel()
test("stateflow mapped"){
viewModel.doubleX.value shouldBe 10
viewModel.x.value = 9
viewModel.doubleX.value shouldBe 18
}
test("combined"){
viewModel.x.value = 10
viewModel.y.value = 3
viewModel.combinedFlow.value shouldBe 30
}
}){
override fun isolationMode(): IsolationMode = IsolationMode.InstancePerLeaf
}
Mini
02/08/2022, 7:12 PMsam
02/08/2022, 7:54 PMMini
02/08/2022, 9:00 PMMini
02/08/2022, 9:03 PM