Why does this test fail? ``` @Test fun test...
# compose
a
Why does this test fail?
Copy code
@Test
    fun testProduceState() {
        var inputState by mutableStateOf(true)
        rule.setContent {
            val outputState by produceState(initialValue = false, inputState) {
                value = async(Dispatchers.Default) {
                    delay(100)
                    !inputState
                }.await()
            }

            Text("$outputState")
        }

        rule.onNodeWithText("false").assertExists()
        inputState = false
        rule.onNodeWithText("true").assertExists()
    }
It seems the test framework thinks the system is “idle” while produceState is still waiting for the computation.
z
I believe it’s because the test framework has no way to know what’s going on on the default dispatcher. As far as compose and even android/espresso are concerned, the main thread is idle. There happens to be some background thread that’s sleeping, but that’s not part of the idle criteria.
a
Right, right