MockStore<St> class
Creates a Redux store that lets you mock actions/reducers.
The MockStore lets you define mock actions/reducers for specific actions.
For more info: https://asyncredux.com AND https://pub.dev/packages/async_redux
Constructors
-
MockStore({required St initialState, Object? environment, Map<
Object?, Object?> props = const {}, bool syncStream = false, TestInfoPrinter? testInfoPrinter, List<ActionObserver< ? actionObservers, List<St> >StateObserver< ? stateObservers, Persistor<St> >St> ? persistor, Persistor<St> ? cloudSync, ModelObserver? modelObserver, ErrorObserver<St> ? errorObserver, WrapReduce<St> ? wrapReduce, @Deprecated("Use `globalWrapError` instead. This will be removed.") WrapError<St> ? wrapError, GlobalWrapError<St> ? globalWrapError, bool? defaultDistinct, CompareBy? immutableCollectionEquality, int? maxErrorsQueued, Map<Type, dynamic> ? mocks})
Properties
- defaultDistinct → bool
-
no setterinherited
- dispatchCount → int
-
no setterinherited
- env → Object?
-
Gets the store environment.
This can be used to create a global value, but scoped to the store.
For example, you could have a service locator, here, or a configuration value.
no setterinherited
-
errors
→ Queue<
UserException> -
Returns a copy of the error queue, containing user exception errors thrown by
dispatched actions. Note that this is a copy of the queue, so you can't modify the original
queue here. Instead, use getAndRemoveFirstError to consume the errors, one by one.
no setterinherited
- forceInternetOnOffSimulation ↔ bool? Function()
-
If you are running tests, you can change forceInternetOnOffSimulation to
simulate the internet connection as ON or OFF for the provided mixins
CheckInternet, AbortWhenNoInternet, and UnlimitedRetryCheckInternet.
getter/setter pairinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- immutableCollectionEquality → CompareBy?
-
If
null(the default), view-models which are immutable collections will be compared by their default equality.If
CompareBy.byDeepEquals, view-models which are immutable collections will be compared by their items, one by one (potentially slow comparison).If
CompareBy.byIdentity, view-models which are immutable collections will be compared by their internals being identical (very fast comparison).no setterinherited - internalMixinProps → _InternalMixinProps
-
Properties used internally by the provided mixins.
You should not use this directly.
finalinherited
- isShutdown → bool
-
no setterinherited
-
mocks
↔ Map<
Type, dynamic> ? -
nullto disable dispatching the action of a certain type.A
MockAction<St>instance to dispatch that action instead, and provide the original action as a getter to the mocked action.A
ReduxAction<St>instance to dispatch that mocked action instead.ReduxAction<St> Function(ReduxAction<St>)to create a mock from the original action.St Function(ReduxAction<St>, St)orFuture<St> Function(ReduxAction<St>, St)to modify the state directly.getter/setter pair - modelObserver → ModelObserver?
-
no setterinherited
-
onChange
→ Stream<
St> -
A stream that emits the current state when it changes.
no setterinherited
-
onReduce
→ Stream<
TestInfo< St> > -
Used by the storeTester.
no setterinherited
-
props
→ Map<
Object?, Object?> -
Gets the store properties.
no setterinherited
- reduceCount → int
-
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- state → St
-
The current state of the app.
no setterinherited
- stateTimestamp → DateTime
-
The timestamp of the current state in the store, in UTC.
no setterinherited
- testInfoPrinter → TestInfoPrinter?
-
no setterinherited
Methods
-
actionsInProgress(
) → Set< ReduxAction< St> > -
Returns an unmodifiable set of the actions on progress.
inherited
-
actionsInProgressEqualTo(
Set< ReduxAction< set) → boolSt> > -
Returns true if the actions in progress are equal to the given set.
inherited
-
addMock(
Type actionType, dynamic mock) → MockStore< St> -
addMocks(
Map< Type, dynamic> mocks) → MockStore<St> -
clearExceptionFor(
Object actionTypeOrList) → void -
Removes the given
actionTypeOrListfrom the list of action types that failed.inherited -
clearMocks(
) → MockStore< St> -
copyActionsInProgress(
) → Set< ReduxAction< St> > -
Returns a copy of the set of actions on progress.
inherited
-
createTestInfoSnapshot(
St state, ReduxAction< St> action, Object? error, Object? processedError, {required bool ini}) → void -
inherited
-
defineState(
St state) → void -
Beware: Changes the state directly. Use only for TESTS.
This will not notify the listeners nor complete wait conditions.
inherited
-
deleteStateFromCloud(
) → Future< void> -
Asks the CloudSync to delete the saved state from the cloud.
inherited
-
deleteStateFromPersistence(
) → Future< void> -
Asks the Persistor to delete the saved state from the cloud.
inherited
-
dispatch(
ReduxAction< St> action, {bool notify = true}) → FutureOr<ActionStatus> -
Dispatches the action, applying its reducer, and possibly changing the store state.
The action may be sync or async.
override
-
dispatchAll(
List< ReduxAction< actions, {bool notify = true}) → List<St> >ReduxAction< St> > -
Dispatches all given
actionsin parallel, applying their reducer, and possibly changing the store state. It returns the same list ofactions, so that you can instantiate them inline, but still get a list of them.inherited -
dispatchAndWait(
ReduxAction< St> action, {bool notify = true}) → Future<ActionStatus> -
Dispatches the action, applying its reducer, and possibly changing the store state.
The action may be sync or async. In both cases, it returns a Future that resolves when
the action finishes.
override
-
dispatchAndWaitAll(
List< ReduxAction< actions, {bool notify = true}) → Future<St> >List< ReduxAction< >St> > -
Dispatches all given
actionsin parallel, applying their reducers, and possibly changing the store state. The actions may be sync or async. It returns a Future that resolves when ALL actions finish.inherited -
dispatchAndWaitAllActions(
ReduxAction< St> action, {bool notify = true, int? timeoutMillis}) → Future<ActionStatus> -
The dispatchAndWaitAllActions should be used in tests only.
inherited
-
dispatchAsync(
ReduxAction< St> action, {bool notify = true}) → Future<ActionStatus> -
override
-
dispatchSync(
ReduxAction< St> action, {bool notify = true}) → ActionStatus -
Dispatches the action, applying its reducer, and possibly changing the store state.
However, if the action is ASYNC, it will throw a StoreException.
override
-
disposeProp(
Object? keyToDispose) → void -
Uses disposeProps to dispose and a single property identified by
its key
keyToDispose, and remove it from the props.inherited -
disposeProps(
[bool predicate({Object? key, Object? value})?]) → void -
The disposeProps method is used to clean up resources associated with
the store's properties, by stopping, closing, ignoring and removing timers,
streams, sinks, and futures that are saved as properties in the store.
inherited
-
exceptionFor(
Object actionTypeOrList) → UserException? -
Returns the UserException of the
actionTypeOrListthat failed.inherited -
getAndRemoveFirstError(
) → UserException? -
Gets the first error from the error queue, and removes it from the queue.
inherited
-
getConnectorTester<
Model> (StatelessWidget widgetConnector) → ConnectorTester< St, Model> -
Helps testing the
StoreConnectors methods, such asonInit,onDisposeandonWillChange.inherited -
getLastPersistedStateFromCloudSync(
) → St? -
Gets, from the CloudSync, the last state that was saved to the cloud.
inherited
-
getLastPersistedStateFromPersistor(
) → St? -
Gets, from the Persistor, the last state that was saved to the local persistence.
inherited
-
initTestInfoController(
) → void -
Turns on testing capabilities, if not already.
inherited
-
initTestInfoPrinter(
TestInfoPrinter testInfoPrinter) → void -
Changes the testInfoPrinter.
inherited
-
isFailed(
Object actionOrTypeOrList) → bool -
Returns true if an
actionOrTypeOrListfailed with an UserException. Note: This method uses the EXACT type inactionOrTypeOrList. Subtypes are not considered.inherited -
isWaiting(
Object actionOrTypeOrList) → bool -
You can use isWaiting and pass it
actionOrTypeOrListto check if:inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
pauseCloudSync(
) → void -
Pause the CloudSync temporarily.
inherited
-
pausePersistor(
) → void -
Pause the Persistor temporarily.
inherited
-
persistAndPauseCloudSync(
) → void -
Saves the current state (if it's not yet saved) to the cloud, then pauses
the CloudSync temporarily.
inherited
-
persistAndPausePersistor(
) → void -
Persists the current state (if it's not yet persisted), then pauses the Persistor
temporarily.
inherited
-
prop<
V> (Object? key) → V -
Gets a property from the store.
This can be used to save global values, but scoped to the store.
For example, you could save timers, streams or futures used by actions.
inherited
-
readStateFromCloudSync(
) → Future< St?> -
Asks the CloudSync to read the state from the cloud.
Important: If you use this, you MUST put this state into the store.
The CloudSync will assume that's the case, and will not work properly otherwise.
inherited
-
readStateFromPersistence(
) → Future< St?> -
Asks the Persistor to read the state from the local persistence.
Important: If you use this, you MUST put this state into the store.
The Persistor will assume that's the case, and will not work properly otherwise.
inherited
-
resumeCloudSync(
) → void -
Resumes persistence by the CloudSync,
after calling pauseCloudSync or persistAndPauseCloudSync.
inherited
-
resumePersistor(
) → void -
Resumes persistence by the Persistor,
after calling pausePersistor or persistAndPausePersistor.
inherited
-
saveInitialStateInCloud(
St initialState) → Future< void> -
Asks the CloudSync to save the
initialStatein the cloud.inherited -
saveInitialStateInPersistence(
St initialState) → Future< void> -
Asks the Persistor to save the
initialStatein the local persistence.inherited -
setProp(
Object? key, Object? value) → void -
Sets a property in the store.
This can be used to save global values, but scoped to the store.
For example, you could save timers, streams or futures used by actions.
inherited
-
shutdown(
) → void -
Call this method to shut down the store.
It won't accept dispatches or change the state anymore.
inherited
-
teardown(
{St? emptyState}) → Future -
Closes down the store so it will no longer be operational.
Only use this if you want to destroy the Store while your app is running.
Do not use this method as a way to stop listening to onChange state changes.
For that purpose, view the onChange documentation.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
waitActionCondition(
bool condition(Set< ReduxAction< actions, ReduxAction<St> >St> ? triggerAction), {bool completeImmediately = false, String completedErrorMessage = "Awaited action condition was already true", int? timeoutMillis}) → Future<(Set< ReduxAction< , ReduxAction<St> >St> ?)> -
Returns a future that completes when some actions meet the given
condition.inherited -
waitActionType(
Type actionType, {bool completeImmediately = false, int? timeoutMillis}) → Future< ReduxAction< St> ?> -
Returns a future that completes when an action of the given type in NOT in progress
(it's not being dispatched):
inherited
-
waitAllActions(
List< ReduxAction< ? actions, {bool completeImmediately = false, int? timeoutMillis}) → Future<St> >void> -
Returns a future that completes when ALL given
actionsfinish dispatching.inherited -
waitAllActionTypes(
List< Type> actionTypes, {bool completeImmediately = false, int? timeoutMillis}) → Future<void> -
Returns a future that completes when ALL actions of the given types are NOT in progress
(none of them are being dispatched):
inherited
-
waitAnyActionTypeFinishes(
List< Type> actionTypes, {int? timeoutMillis}) → Future<ReduxAction< St> > -
Returns a future which will complete when ANY action of the given types FINISHES
dispatching. IMPORTANT: This method is different from the other similar methods, because
it does NOT complete immediately if no action of the given types is in progress. Instead,
it waits until an action of the given types finishes dispatching, even if they
were not yet in progress when the method was called.
inherited
-
waitCondition(
bool condition(St), {bool completeImmediately = true, int? timeoutMillis}) → Future< ReduxAction< St> ?> -
Returns a future which will complete when the given state
conditionis true.inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited