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

Commit 8f72d9d2 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Update runTestWithSnapshots documentation" into main

parents 9ca08656 1e40838b
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() }