TestNavigatorState


class TestNavigatorState


An implementation of NavigatorState that allows testing a androidx.navigation.Navigator in isolation (i.e., without requiring a androidx.navigation.NavController).

An optional context can be provided to allow for the usages of androidx.lifecycle.AndroidViewModel within the created NavBackStackEntry instances.

The Lifecycle of all NavBackStackEntry instances added to this TestNavigatorState will be updated as they are added and removed from the state. This work is kicked off on the coroutineDispatcher.

Summary

Public constructors

TestNavigatorState(
    context: Context?,
    coroutineDispatcher: CoroutineDispatcher
)

Public functions

open <Error class: unknown class>
createBackStackEntry(
    destination: <Error class: unknown class>,
    arguments: Bundle?
)
open Unit
open Unit
pop(popUpTo: <Error class: unknown class>, saveState: Boolean)
open Unit
popWithTransition(
    popUpTo: <Error class: unknown class>,
    saveState: Boolean
)
open Unit
open Unit
<Error class: unknown class>
restoreBackStackEntry(
    previouslySavedEntry: <Error class: unknown class>
)

Restore a previously saved NavBackStackEntry.

Public constructors

TestNavigatorState

Added in 2.4.0
TestNavigatorState(
    context: Context? = null,
    coroutineDispatcher: CoroutineDispatcher = Dispatchers.Main.immediate
)

Public functions

open fun createBackStackEntry(
    destination: <Error class: unknown class>,
    arguments: Bundle?
): <Error class: unknown class>
open fun markTransitionComplete(entry: <Error class: unknown class>): Unit
open fun pop(popUpTo: <Error class: unknown class>, saveState: Boolean): Unit
open fun popWithTransition(
    popUpTo: <Error class: unknown class>,
    saveState: Boolean
): Unit
open fun prepareForTransition(entry: <Error class: unknown class>): Unit
open fun push(backStackEntry: <Error class: unknown class>): Unit
fun restoreBackStackEntry(
    previouslySavedEntry: <Error class: unknown class>
): <Error class: unknown class>

Restore a previously saved NavBackStackEntry. You must have previously called pop with previouslySavedEntry and true.