android-components / mozilla.components.support.android.test / androidx.lifecycle.LiveData / awaitValue

awaitValue

fun <T> LiveData<T>.awaitValue(timeout: Long = 1, unit: TimeUnit = TimeUnit.SECONDS): T? (source)

Subscribes to the LiveData object and blocks until a value was observed. Returns the value or throws InterruptedException if no value was observed in the given timeout (using unit).

This is helpful for tests using LiveData objects that won’t contain any data unless observed (e.g. LiveData objects returned by Room).