Package-level declarations

Types

Link copied to clipboard

This is a scheduler for coroutines used in tests, providing the delay-skipping behavior.

Link copied to clipboard

A test dispatcher that can interface with a TestCoroutineScheduler.

Link copied to clipboard
expect class TestResult

A test result.

actual typealias TestResult = JsPromiseInterfaceForTesting
actual typealias TestResult = Unit
actual typealias TestResult = Unit
actual typealias TestResult = JsPromiseInterfaceForTesting
actual typealias TestResult = Unit
Link copied to clipboard
sealed interface TestScope : CoroutineScope

A coroutine scope that for launching test coroutines.

Functions

Link copied to clipboard

Moves the virtual clock of this dispatcher forward by the specified amount, running the scheduled tasks in the meantime.

Link copied to clipboard

Advances the testScheduler to the point where there are no tasks remaining.

Advances the testScheduler to the point where there are no tasks remaining.

Link copied to clipboard

Resets state of the Dispatchers.Main to the original main dispatcher.

Link copied to clipboard
fun runBlockingTest(context: CoroutineContext = EmptyCoroutineContext, testBody: suspend TestCoroutineScope.() -> Unit)

Executes a testBody inside an immediate execution dispatcher.

Link copied to clipboard

Convenience method for calling runBlockingTest on an existing TestCoroutineDispatcher.

Convenience method for calling runBlockingTest on an existing TestCoroutineScope.

fun TestScope.runBlockingTest(block: suspend TestScope.() -> Unit)

Convenience method for calling runBlockingTestOnTestScope on an existing TestScope.

Link copied to clipboard
fun runBlockingTestOnTestScope(context: CoroutineContext = EmptyCoroutineContext, testBody: suspend TestScope.() -> Unit)

A version of runBlockingTest that works with TestScope.

Link copied to clipboard

Run any tasks that are pending at the current virtual time, according to the testScheduler.

Run any tasks that are pending at the current virtual time, according to the testScheduler.

Link copied to clipboard
fun runTest(context: CoroutineContext = EmptyCoroutineContext, dispatchTimeoutMs: Long, testBody: suspend TestScope.() -> Unit): TestResult
fun runTest(context: CoroutineContext = EmptyCoroutineContext, timeout: Duration = DEFAULT_TIMEOUT.getOrThrow(), testBody: suspend TestScope.() -> Unit): TestResult

Executes testBody as a test in a new coroutine, returning TestResult.

Link copied to clipboard
fun TestScope.runTest(dispatchTimeoutMs: Long, testBody: suspend TestScope.() -> Unit): TestResult

Performs runTest on an existing TestScope.

fun TestScope.runTest(timeout: Duration = DEFAULT_TIMEOUT.getOrThrow(), testBody: suspend TestScope.() -> Unit): TestResult

Performs runTest on an existing TestScope. See the documentation for runTest for details.

fun TestCoroutineScope.runTest(dispatchTimeoutMs: Long = DEFAULT_DISPATCH_TIMEOUT_MS, block: suspend TestCoroutineScope.() -> Unit): TestResult

Runs a test in a TestCoroutineScope based on this one.

Link copied to clipboard
fun runTestWithLegacyScope(context: CoroutineContext = EmptyCoroutineContext, dispatchTimeoutMs: Long = DEFAULT_DISPATCH_TIMEOUT_MS, testBody: suspend TestCoroutineScope.() -> Unit)

This is an overload of runTest that works with TestCoroutineScope.

Link copied to clipboard

Sets the given dispatcher as an underlying dispatcher of Dispatchers.Main. All subsequent usages of Dispatchers.Main will use the given dispatcher under the hood.

Link copied to clipboard
fun StandardTestDispatcher(scheduler: TestCoroutineScheduler? = null, name: String? = null): TestDispatcher

Creates an instance of a TestDispatcher whose tasks are run inside calls to the scheduler.

Link copied to clipboard
fun TestScope(context: CoroutineContext = EmptyCoroutineContext): TestScope

Creates a TestScope.

Link copied to clipboard

Creates an instance of an unconfined TestDispatcher.