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

theapache64

02/04/2022, 6:34 AM
⁉️ I am having trouble with
ComposeTestRule#advanceTimeBy
method. It doesn’t work as expected with animations. ▶️ Here’s more details : https://stackoverflow.com/questions/70982285/compose-advancetimeby-doesnt-work-with-animation.
🐛 1
d

Doris Liu

02/05/2022, 4:50 AM
Some initial investigation showed that the animations from
AnimatedVisibility
were never added to the Transition, because measure() was not called and slide animation is initialized during measure. As a result, we ended up having an empty Transition that finished right away. That's why the test failed. Note that adding
advanceTimeByFrame()
before
advanceTimeBy(1500)
seems to allow the test to pass. This might be useful for narrowing down the cause. Could you file a bug please?
t

theapache64

02/05/2022, 5:22 AM
Workaround works! Confirmed. Sure. I’ll file a ticket 👍
🙏 1
r

Rohil Chodankar

05/09/2022, 4:55 PM
Hey, I am fairly new to compose but for some reason, after updating to compose 1.1.1.
Copy code
rule.onNodeWithText("title").assertDoesNotExist()
    rule.mainClock.autoAdvance = false

    rule.runOnUiThread { expanded = true }
    rule.mainClock.advanceTimeByFrame() // Trigger the popup
    rule.waitForIdle()
    rule.mainClock.advanceTimeByFrame() // Kick off the animation
    rule.mainClock.advanceTimeBy(InTransitionDuration.toLong())
    rule.onNodeWithText("title").assertExists()
the code assertExists() doesn't complete and the test hangs on that step. We run the test as instrumentation and unit test using Robolectric. The instrumentation test seems to get executed but facing problem with running as unit test. Any thoughts ? @Doris Liu @theapache64
d

Doris Liu

05/09/2022, 6:41 PM
Two questions: 1. Can you log the value of
InTransitionDuration
, to double check it's within reasonable range and isn't nano-second based. 2. Did this work before 1.1.1?
r

Rohil Chodankar

05/09/2022, 6:46 PM
1. We have set the
InTransitionDuration
to 120, thats the same to the duration of the animation. 2. Yes, it worked with compose version 1.0.5 (currently used version). But as we were trying to migrate to 1.1.0 or 1.1.1, it fails on both version
d

Doris Liu

05/09/2022, 6:46 PM
In that case, this sounds like a bug to me. Could you file a bug, including the snippet?
r

Rohil Chodankar

05/09/2022, 6:50 PM
sure. Is there anything specific related animation that got changed in the 1.1.0 version? Running the test as instrumentation seems to work fine but causing a problem while running it as unit test with robolectric
d

Doris Liu

05/09/2022, 7:11 PM
Here's all the changes in animation: https://developer.android.com/jetpack/androidx/releases/compose-animation Nothing stands out. It could also be a change in testing that caused the issue.
🙏 1
b

Bryan Herbst

05/10/2022, 2:05 PM
A little more context on this (I work with Rohil) - this is only happening in our Robolectric Junit tests, not instrumented tests. I suspect there’s something funky happening with Robolectric’s shadows.
Still digging in more, but it appears that
RobolectricIdlingStrategy.runUntilIdle()
is not finishing in our
assertExists()
14 Views