|
|
|
@ -4,6 +4,7 @@ import androidx.compose.runtime.Composable
|
|
|
|
|
import androidx.compose.runtime.MonotonicFrameClock |
|
|
|
|
import kotlinx.browser.document |
|
|
|
|
import kotlinx.browser.window |
|
|
|
|
import kotlinx.coroutines.suspendCancellableCoroutine |
|
|
|
|
import kotlinx.coroutines.CoroutineScope |
|
|
|
|
import kotlinx.coroutines.MainScope |
|
|
|
|
import kotlinx.coroutines.promise |
|
|
|
@ -84,12 +85,16 @@ class TestScope : CoroutineScope by MainScope() {
|
|
|
|
|
* Suspends until [element] observes any change to its html. |
|
|
|
|
*/ |
|
|
|
|
suspend fun waitForChanges(element: HTMLElement = root) { |
|
|
|
|
suspendCoroutine<Unit> { continuation -> |
|
|
|
|
suspendCancellableCoroutine<Unit> { continuation -> |
|
|
|
|
val observer = MutationObserver { _, observer -> |
|
|
|
|
continuation.resume(Unit) |
|
|
|
|
observer.disconnect() |
|
|
|
|
} |
|
|
|
|
observer.observe(element, MutationObserverOptions) |
|
|
|
|
|
|
|
|
|
continuation.invokeOnCancellation { |
|
|
|
|
observer.disconnect() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -97,8 +102,14 @@ class TestScope : CoroutineScope by MainScope() {
|
|
|
|
|
* Suspends until recomposition completes. |
|
|
|
|
*/ |
|
|
|
|
suspend fun waitForRecompositionComplete() { |
|
|
|
|
suspendCoroutine<Unit> { continuation -> |
|
|
|
|
suspendCancellableCoroutine<Unit> { continuation -> |
|
|
|
|
waitForRecompositionCompleteContinuation = continuation |
|
|
|
|
|
|
|
|
|
continuation.invokeOnCancellation { |
|
|
|
|
if (waitForRecompositionCompleteContinuation === continuation) { |
|
|
|
|
waitForRecompositionCompleteContinuation = null |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|