StoreTester<St> class

Helps testing the store, actions, and sync/async reducers.

For more info, see: https://pub.dartlang.org/packages/async_redux

Constructors

StoreTester({required St initialState, TestInfoPrinter? testInfoPrinter, List<Type>? ignore, bool syncStream = false, ErrorObserver<St>? errorObserver, bool shouldThrowUserExceptions = false, Map<Type, dynamic>? mocks})
The StoreTester makes it easy to test both sync and async reducers. You may dispatch some action, wait for it to finish or wait until some arbitrary condition is met, and then check the resulting state.
StoreTester.from(Store<St> store, {TestInfoPrinter? testInfoPrinter, List<Type>? ignore})
Create a StoreTester from a store that already exists.
StoreTester.simple(Store<St> _store)
Create a StoreTester from a store that already exists, but don't print anything to the console.

Properties

currentTestInfo TestInfo<St>
The current TestInfo.
no setter
hashCode int
The hash code for this object.
no setterinherited
ignore List<Type>
Returns a mutable copy of the global ignore list.
no setter
lastInfo TestInfo<St>
The last TestInfo read after some wait method.
getter/setter pair
mocks Map<Type, dynamic>?
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
state → St
no setter
store Store<St>
no setter

Methods

addMock(Type actionType, dynamic mock) MockStore<St>
addMocks(Map<Type, dynamic> mocks) MockStore<St>
cancel() Future
clearMocks() MockStore<St>
defineState(St state) → void
dispatch(ReduxAction<St> action, {bool notify = true}) FutureOr<ActionStatus>
dispatchAndWait(ReduxAction<St> action, {bool notify = true}) Future<ActionStatus>
dispatchAndWaitGetInfo(ReduxAction<St> action) Future<TestInfo<St>>
Dispatches action, and then waits until it finishes. Returns the info after the action finishes. Ignores other actions.
dispatchAsync(ReduxAction<St> action, {bool notify = true}) Future<ActionStatus>
dispatchState(St state) Future<TestInfo<St>>
Dispatches an action that changes the current state to the one provided by you. Then, runs until that action is dispatched and finished (ignoring other actions). Returns the info after the action finishes, containing the given state.
dispatchSync(ReduxAction<St> action, {bool notify = true}) ActionStatus
getConnectorTester<Model>(StatelessWidget widgetConnector) ConnectorTester<St, Model>
Helps testing the StoreConnectors methods, such as onInit, onDispose and onWillChange.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
wait(Type actionType) Future<TestInfo<St>>
Expects one action of the given type to be dispatched, and waits until it finishes. Returns the info after the action finishes. Will fail with an exception if an unexpected action is seen.
waitAll(List<Type> actionTypes, {List<Type>? ignore}) Future<TestInfoList<St>>
Runs until all given actions types are dispatched, in order. Waits until all of them are finished. Returns the info after all actions finish. Will fail with an exception if an unexpected action is seen, or if any of the expected actions are dispatched in the wrong order.
waitAllGetLast(List<Type> actionTypes, {List<Type>? ignore}) Future<TestInfo<St>>
Runs until all given actions types are dispatched, in order. Waits until all of them are finished. Returns the info after all actions finish. Will fail with an exception if an unexpected action is seen, or if any of the expected actions are dispatched in the wrong order.
waitAllUnordered(List<Type> actionTypes, {int? timeoutInSeconds, List<Type>? ignore}) Future<TestInfoList<St>>
The same as waitAllUnorderedGetLast, but instead of returning just the last info, it returns a list with the end info for each action.
waitAllUnorderedGetLast(List<Type> actionTypes, {int? timeoutInSeconds, List<Type>? ignore}) Future<TestInfo<St>>
Runs until all given actions types are dispatched, in any order. Waits until all of them are finished. Returns the info after all actions finish. Will fail with an exception if an unexpected action is seen.
waitCondition(StateCondition<St> condition, {bool testImmediately = true, bool ignoreIni = true, int? timeoutInSeconds}) Future<TestInfoList<St>>
Runs until the predicate function condition returns true. This function will receive each testInfo, from where it can access the state, action, errors etc. When testImmediately is true (the default), it will test the condition immediately when the method is called. If the condition is true, the method will return immediately, without waiting for any actions to be dispatched. When testImmediately is false, it will only test the condition once an action is dispatched. Only END states will be received, unless you pass ignoreIni as false. Returns a list with all info until the condition is met.
waitConditionGetLast(StateCondition<St> condition, {bool testImmediately = true, bool ignoreIni = true, int? timeoutInSeconds}) Future<TestInfo<St>>
Runs until the predicate function condition returns true. This function will receive each testInfo, from where it can access the state, action, errors etc. When testImmediately is true (the default), it will test the condition immediately when the method is called. If the condition is true, the method will return immediately, without waiting for any actions to be dispatched. When testImmediately is false, it will only test the condition once an action is dispatched. Only END states will be received, unless you pass ignoreIni as false. Returns the info after the condition is met.
waitUntil(Type actionType, {int? timeoutInSeconds}) Future<TestInfo<St>>
Runs until an action of the given type is dispatched, and then waits until it finishes. Returns the info after the action finishes. Ignores other actions types.
waitUntilAction(ReduxAction<St> action, {int? timeoutInSeconds}) Future<TestInfo<St>>
Runs until the exact given action is dispatched, and then waits until it finishes. Returns the info after the action finishes. Ignores other actions.
waitUntilAll(List<Type> actionTypes, {bool ignoreIni = true, int? timeoutInSeconds}) Future<TestInfoList<St>>
Runs until all actions of the given types are dispatched and finish, in any order. Returns a list with all info until the last action finishes. Ignores other actions types.
waitUntilAllGetLast(List<Type> actionTypes, {bool ignoreIni = true, int? timeoutInSeconds}) Future<TestInfo<St>>
Runs until all actions of the given types are dispatched and finish, in any order. Returns the info after they all finish. Ignores other actions types.
waitUntilAny(List<Type> actionTypes, {int? timeoutInSeconds}) Future<TestInfo<St>>
Runs until an action of the given types is dispatched, and then waits until it finishes. Returns the info after the action finishes. Ignores other actions types.
waitUntilError({Object? error, Object? processedError, int? timeoutInSeconds}) Future<TestInfoList<St>>
If error is a Type, runs until after an action throws an error of this exact type. If error is NOT a Type, runs until after an action throws this error (using equals).
waitUntilErrorGetLast({Object? error, Object? processedError, int? timeoutInSeconds}) Future<TestInfo<St>>
If error is a Type, runs until after an action throws an error of this exact type. If error is NOT a Type, runs until after an action throws this error (using equals).

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

defaultNewStorePrinter VoidCallback
getter/setter pair
defaultTestInfoPrinter TestInfoPrinter
getter/setter pair
defaultTimeout int
The default timeout in seconds is 10 minutes. This value is not final and can be modified.
getter/setter pair
printDefaultDebugInfo bool
If the default debug info should be printed to the console or not.
getter/setter pair