Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1e40838b authored by Jordan Demeulenaere's avatar Jordan Demeulenaere
Browse files

Update runTestWithSnapshots documentation

Bug: 387321113
Test: N/A
Flag: EXEMPT kdoc update
Change-Id: Ib2b3448b6ba8c28d5cee6121b2c69f70abf9236b
parent 4a5b3c4d
Loading
Loading
Loading
Loading
+4 −6
Original line number Diff line number Diff line
@@ -17,18 +17,16 @@
package com.android.systemui.compose

import androidx.compose.runtime.snapshots.Snapshot
import com.android.systemui.kosmos.runCurrent
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.UnconfinedTestDispatcher
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest

/**
 * Runs the given test [block] in a [TestScope] that's set up such that the Compose snapshot state
 * is settled eagerly. This is the Compose equivalent to using an [UnconfinedTestDispatcher] or
 * using [runCurrent] a lot.
 * writes are properly applied to the global snapshot. This is for instance necessary if your test
 * is using `snapshotFlow {}` or any other mechanism that is observing the global snapshot.
 *
 * Note that this shouldn't be needed or used in a Compose test environment.
 * Note that this isn't needed in a Compose test environment, e.g. if you use the
 * `Compose(Content)TestRule`.
 */
fun TestScope.runTestWithSnapshots(block: suspend TestScope.() -> Unit) {
    val handle = Snapshot.registerGlobalWriteObserver { Snapshot.sendApplyNotifications() }