Skip to content

Instantly share code, notes, and snippets.

View joetimmins's full-sized avatar

Joe Timmins joetimmins

View GitHub Profile
@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
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>