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