MockCommand<TParam, TResult> class

MockCommand allows you to easily mock an RxCommand for your Unit and UI tests Mocking a command with mockito https://pub.dartlang.org/packages/mockito has its limitations.

Inheritance

Constructors

MockCommand({Stream<bool>? restriction, bool emitInitialCommandResult = false, bool emitLastResult = false, bool emitsLastValueToNewSubscriptions = false, TResult? initialLastResult, String? debugName})
Factory constructor that can take an optional observable to control if the command can be executet
factory

Properties

canExecute Stream<bool>
Observable stream that issues a bool on any change of the current executable state of the command. Meaning if the command cann be executed or not. This will issue false while the command executes but also if the command receives a false from the canExecute Observable that you can pass when creating the Command
no setterinherited
executionCount int
Number of times execute or the command directly was called
getter/setter pair
first Future<TResult>
The first element of this stream.
no setterinherited
hashCode int
The hash code for this object.
no setterinherited
isBroadcast bool
Whether this stream is a broadcast stream.
no setterinherited
isEmpty Future<bool>
Whether this stream contains any elements.
no setterinherited
isExecuting Stream<bool>
Observable stream that issues a bool on any execution state change of the command
no setterinherited
last Future<TResult>
The last element of this stream.
no setterinherited
lastPassedValueToExecute ↔ TParam?
the last value that was passed when execute or the command directly was called
getter/setter pair
lastResult ↔ TResult?
The result of the last successful call to execute. This is especially handy to use as initialData of Flutter StreamBuilder
getter/setter pairinherited
length Future<int>
The number of elements in this stream.
no setterinherited
next Future<TResult>
This property is a utility which allows us to chain RxCommands together.
no setterinherited
results Stream<CommandResult<TParam, TResult>>
emits CommandResult<TRESULT> the combined state of the command, which is often easier in combination with Flutter StreamBuilder because you have all state information at one place.
no setterinherited
returnValuesForNextExecute List<CommandResult<TParam, TResult>>?
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
single Future<TResult>
The single element of this stream.
no setterinherited
throwExceptions bool
By default RxCommand will catch all exceptions during execution of the command. And publish them on .thrownExceptions and in the CommandResult. If don't want this and have exceptions thrown, set this to true.
getter/setter pairinherited
thrownExceptions Stream
When subribing to thrownExceptionsyou will every excetpion that was thrown in your handler function as an event on this Observable. If no subscription exists the Exception will be rethrown
no setterinherited

Methods

any(bool test(TResult element)) Future<bool>
Checks whether test accepts any element provided by this stream.
inherited
asBroadcastStream({void onListen(StreamSubscription<TResult> subscription)?, void onCancel(StreamSubscription<TResult> subscription)?}) Stream<TResult>
Returns a multi-subscription stream that produces the same events as this.
inherited
asyncExpand<E>(Stream<E>? convert(TResult event)) Stream<E>
Transforms each element into a sequence of asynchronous events.
inherited
asyncMap<E>(FutureOr<E> convert(TResult event)) Stream<E>
Creates a new stream with each data event of this stream asynchronously mapped to a new event.
inherited
call([TParam? param]) → void
This makes RxCommand a callable class, so instead of myCommand.execute() you can write myCommand()
inherited
cast<R>() Stream<R>
Adapt this stream to be a Stream<R>.
inherited
contains(Object? needle) Future<bool>
Returns whether needle occurs in the elements provided by this stream.
inherited
dispose() → void
If you don't need a command any longer it is a good practise to dispose it to make sure all stream subscriptions are cancelled to prevent memory leaks
inherited
distinct([bool equals(TResult previous, TResult next)?]) Stream<TResult>
Skips data events if they are equal to the previous data event.
inherited
drain<E>([E? futureValue]) Future<E>
Discards all data on this stream, but signals when it is done or an error occurred.
inherited
elementAt(int index) Future<TResult>
Returns the value of the indexth data event of this stream.
inherited
endExecutionNoData() → void
endExecutionNoData will issue a CommandResult with data: null error: null isExecuting : false
endExecutionWithData(TResult data) → void
endExecutionWithData will issue a CommandResult with data: data error: null isExecuting : false
endExecutionWithError(String message) → void
endExecutionWithData will issue a CommandResult with data: null error: Exeption(message) isExecuting : false
every(bool test(TResult element)) Future<bool>
Checks whether test accepts all elements provided by this stream.
inherited
execute([TParam? param]) → void
Can either be called directly or by calling the object itself because RxCommands are callable classes Will increase executionCount and assign lastPassedValueToExecute the value of param If you have queued a result with queueResultsForNextExecuteCall it will be copies tho the output stream. isExecuting, canExecute and results will work as with a real command.
override
expand<S>(Iterable<S> convert(TResult element)) Stream<S>
Transforms each element of this stream into a sequence of elements.
inherited
firstWhere(bool test(TResult element), {TResult orElse()?}) Future<TResult>
Finds the first element of this stream matching test.
inherited
fold<S>(S initialValue, S combine(S previous, TResult element)) Future<S>
Combines a sequence of values by repeatedly applying combine.
inherited
forEach(void action(TResult element)) Future<void>
Executes action on each element of this stream.
inherited
handleError(Function onError, {bool test(dynamic error)?}) Stream<TResult>
Creates a wrapper Stream that intercepts some errors from this stream.
inherited
join([String separator = ""]) Future<String>
Combines the string representation of elements into a single string.
inherited
lastWhere(bool test(TResult element), {TResult orElse()?}) Future<TResult>
Finds the last element in this stream matching test.
inherited
listen(void onData(TResult value)?, {Function? onError, void onDone()?, bool? cancelOnError}) StreamSubscription<TResult>
Adds a subscription to this stream.
inherited
map<S>(S convert(TResult event)) Stream<S>
Transforms each element of this stream into a new stream event.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
pipe(StreamConsumer<TResult> streamConsumer) Future
Pipes the events of this stream into streamConsumer.
inherited
queueResultsForNextExecuteCall(List<CommandResult<TParam, TResult>> values) → dynamic
to be able to simulate any output of the command when it is called you can here queue the output data for the next exeution call
reduce(TResult combine(TResult previous, TResult element)) Future<TResult>
Combines a sequence of values by repeatedly applying combine.
inherited
singleWhere(bool test(TResult element), {TResult orElse()?}) Future<TResult>
Finds the single element in this stream matching test.
inherited
skip(int count) Stream<TResult>
Skips the first count data events from this stream.
inherited
skipWhile(bool test(TResult element)) Stream<TResult>
Skip data events from this stream while they are matched by test.
inherited
startExecution([TParam? param]) → void
For a more fine grained control to simulate the different states of an RxCommand there are these functions startExecution will issue a CommandResult with paramData: null data: null error: null isExecuting : true
take(int count) Stream<TResult>
Provides at most the first count data events of this stream.
inherited
takeWhile(bool test(TResult element)) Stream<TResult>
Forwards data events while test is successful.
inherited
timeout(Duration timeLimit, {void onTimeout(EventSink<TResult> sink)?}) Stream<TResult>
Creates a new stream with the same events as this stream.
inherited
toList() Future<List<TResult>>
Collects all elements of this stream in a List.
inherited
toSet() Future<Set<TResult>>
Collects the data of this stream in a Set.
inherited
toString() String
A string representation of this object.
inherited
transform<S>(StreamTransformer<TResult, S> streamTransformer) Stream<S>
Applies streamTransformer to this stream.
inherited
where(bool test(TResult event)) Stream<TResult>
Creates a new stream from this stream that discards some elements.
inherited

Operators

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