https://kotlinlang.org logo
#compose
Title
# compose
j

Ji Sungbin

02/15/2023, 9:37 PM
Hi, why is recomposition not working in this Compose UI test code?
Copy code
@get:Rule
val composeTestRule = createComposeRule()

@Test
fun test_recomposition() {
    var recomposed = false
    composeTestRule.setContent {
        Box {
            println("composed!")
            if (!recomposed) {
                recomposed = true
                currentRecomposeScope.invalidate() // <--- try recomposition here
            }
        }
    }
}
The “composed” log is displayed only once.
y

yschimke

02/16/2023, 6:06 AM
Maybe try doing some check after setContent that causes it to wait for it to idle.
Check the box is visible for example
j

Ji Sungbin

02/16/2023, 3:34 PM
Hi Yuri Schimke, thanks for the help! I’ll try to do as you say.
50 Views