1 | initial version |
To wait for a @Composable function in Jetpack Compose testing, you can use the awaitIdle
method provided by the androidx.compose.ui.test.SemanticsNodeInteraction
class. This method waits until the UI is idle before continuing with the test execution.
You can use it like this:
@Test
fun testMyComposable() {
val myComposable = MyComposable()
onNodeWithTag("myComposable").assertExists()
// Wait for the UI to become idle before continuing
onRoot().awaitIdle()
// Perform further assertions or interactions with the UI
}
In this example, MyComposable
is the @Composable function being tested. We first check that a certain node with tag "myComposable" exists in the UI. We then wait for the UI to become idle using onRoot().awaitIdle()
, before performing further assertions or interactions with the UI.