is called and hence Text does not show. But during testing,
LaunchedEffect
is called first and then
onFocusChanged
is called and Text shows up. I can’t figure out why the order is different in simple calling and in testing. Kindly guide me if someone has any idea what is going on. Code attached in the thread.
Abdul Hafeez Sajid
12/21/2022, 10:01 AM
Copy code
@Composable
fun someComposable() {
var text by remember {
mutableStateOf("")
}
var show by remember {
mutableStateOf(false)
}
LaunchedEffect(key1 = Unit, block = {
Log.d(TAG, "someComposable(): LaunchedEffect()")
show = false
})
BasicTextField(
value = text,
onValueChange = { text = it },
modifier = Modifier.onFocusChanged {
Log.d(TAG, "someComposable(): onFocusChanged()")
show = true
})
if (show) {
Text(text = "Text", Modifier.testTag("text_tag"))
}
}
@Test
fun testSomeComposable() {
composeTestRule.setContent {
someComposable()
}
composeTestRule.onNodeWithTag("text_tag", true).assertExists()
}
z
Zach Klippenstein (he/him) [MOD]
12/21/2022, 11:01 PM
What version of compose is this?
Zach Klippenstein (he/him) [MOD]
12/22/2022, 12:46 AM
This is almost certainly because until the very latest 1.4.0 alpha, the order in which coroutine dispatch happened relative to applyChanges was very different in production than in the test runtime. It’s partially fixed in the latest alpha and should be completely fixed in the next alpha (January)