mvrx-mocking / com.airbnb.mvrx.mocking / MockBehavior

MockBehavior

data class MockBehavior

Different types of mock setups that can be provided.

When a mocked view model is created, "existing" view model expectations are ignored, and the viewmodel is created from mocked state instead of throwing an exception.

However, it is up to the caller to make sure that a ViewModel of the expected type doesn't already exist in the view model store, otherwise the framework will use that one instead of allowing us to create a new mocked one, so make sure to clear the store of any previously created viewmodels first.

Types

InitialStateMocking

enum class InitialStateMocking

Describes how a custom mocked state is applied to initialize a new ViewModel.

StateStoreBehavior

enum class StateStoreBehavior

Constructors

<init>

MockBehavior(initialStateMocking: MockBehavior.InitialStateMocking = InitialStateMocking.None, blockExecutions: BlockExecutions = MavericksViewModelConfig.BlockExecutions.No, stateStoreBehavior: MockBehavior.StateStoreBehavior = StateStoreBehavior.Normal, subscribeViewToStateUpdates: Boolean = true)

Different types of mock setups that can be provided.

Properties

blockExecutions

val blockExecutions: BlockExecutions

initialStateMocking

val initialStateMocking: MockBehavior.InitialStateMocking

stateStoreBehavior

val stateStoreBehavior: MockBehavior.StateStoreBehavior

subscribeViewToStateUpdates

val subscribeViewToStateUpdates: Boolean

If true, when a view registers a ViewModel via a delegate the view will be subscribed to changes to the state view MavericksView.postInvalidate. This is the normal behavior of MvRx. This can be set to false so that a Fragment is not updated for state changes during tests.