This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@OptIn(ExperimentalCoroutinesApi::class) | |
fun <T : Any> Flow<T>.checkValues( | |
vararg actions: suspend () -> Unit, | |
assert: List<T>.() -> Unit, | |
) = runTest { | |
// replace main & viewModelScope with the standard test dispatcher | |
Dispatchers.setMain(StandardTestDispatcher(testScheduler)) | |
val results = mutableListOf<T>() | |
// collect the flow on an unconfined test dispatcher |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun <T : Any> MutableLiveData<T>.update(transform: (T) -> T) { | |
val current = value ?: return | |
postValue(transform(current)) | |
} | |
class TinyViewModel() { | |
private val initialState = UiState(greeting = "nah mate") | |
private val _uiState = MutableLiveData(initialState) | |
val uiState = _uiState as LiveData<String> | |