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 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.
read-only
hashCode int
The hash code for this object. [...]
read-only, inherited
ignore List<Type>
Returns a mutable copy of the global ignore list.
read-only
lastInfo TestInfo<St>
The last TestInfo read after some wait method.
read / write
mocks Map<Type, dynamic>
read / write
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited
state → St
read-only
store Store<St>
read-only

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}) → void
dispatchFuture(ReduxAction<St> action, {bool notify: true}) Future<void>
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
toString() String
Returns 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: defaultTimeout, 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: defaultTimeout, 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: defaultTimeout}) 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: defaultTimeout}) 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: defaultTimeout}) 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: defaultTimeout}) 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. [...]
waitUntilError({Object error, Object processedError, int timeoutInSeconds: defaultTimeout}) 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: defaultTimeout}) 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
read / write
defaultTestInfoPrinter TestInfoPrinter
read / write
printDefaultDebugInfo bool
If the default debug info should be printed to the console or not.
read / write

Constants

defaultTimeout → const int
The global default timeout for the wait functions.
500