MockCommand<TParam, TResult> class
MockCommand
allows you to easily mock an Command for your Unit and UI tests
Mocking a command with mockito
https://pub.dartlang.org/packages/mockito has its limitations.
- Inheritance
-
- Object
- ChangeNotifier
- ValueNotifier<
TResult?> - Command<
TParam, TResult?> - MockCommand
- Available Extensions
Constructors
-
MockCommand({required TResult initialValue, bool noParamValue = false, bool noResult = false, ValueListenable<
bool> ? restriction, bool includeLastResultInCommandResult = false, bool? catchAlways, String? debugName}) -
constructor that can take an optional
ValueListenable
to control if the command can be execute if the wrapped function hasvoid
as return typenoResult
has to betrue
Properties
-
canExecute
→ ValueListenable<
bool> -
ValueListenable<bool>
that changes its value on any change of the current executability state of the command. Meaning if the command can be executed or not. This will issuefalse
while the command executes, but also if the command receives a false from the canExecuteValueListenable
that you can pass when creating the Command. its value isrestriction.value && !isExecuting.value
no setterinherited - executionCount ↔ int
-
Number of times execute or the command directly was called
getter/setter pair
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasListeners → bool
-
Whether any listeners are currently registered.
no setterinherited
-
isExecuting
→ ValueListenable<
bool> -
ValueListenable
that changes its value on any change of the execution state change of the commandno setterinherited - lastPassedValueToExecute ↔ TParam?
-
the last value that was passed when execute or the command directly was called
getter/setter pair
-
results
→ ValueListenable<
CommandResult< TParam?, TResult?> > -
emits
CommandResult<TResult>
the combined state of the command, which is often easier in combination with Flutter'sValueListenableBuilder
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
-
thrownExceptions
→ ValueListenable<
CommandError?> -
ValueListenable<CommandError>
that reflects the Error State of the command it value is reset tonull
at the beginning of every command execution if the wrapped function throws an error, its value is set to the error is wrapped in anCommandError
no setterinherited - value ↔ TResult?
-
The current value stored in this notifier.
getter/setter pairinherited
Methods
-
addListener(
VoidCallback listener) → void -
Register a closure to be called when the object changes.
inherited
-
call(
[TParam? param]) → void -
This makes Command a callable class, so instead of
myCommand.execute()
you can writemyCommand()
inherited -
dispose(
) → void -
If you don't need a command any longer it is a good practise to
dispose it to make sure all registered notification handlers are remove to
prevent memory leaks
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: Exception(message
) isExecuting : false -
execute(
[TParam? param]) → void -
Can either be called directly or by calling the object itself because Commands 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 -
executeWithFuture(
[TParam? param]) → Future< TResult?> -
Executes an async Command an returns a Future that completes as soon as
the Command completes. This is especially useful if you use a
RefreshIndicator
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifyListeners(
) → void -
Call all the registered listeners.
inherited
-
queueResultsForNextExecuteCall(
List< CommandResult< values) → voidTParam, TResult> > - to be able to simulate any output of the command when it is called you can here queue the output data for the next execution call
-
removeListener(
VoidCallback listener) → void -
Remove a previously registered closure from the list of closures that are
notified when the object changes.
inherited
-
startExecution(
[TParam? param]) → void -
For a more fine grained control to simulate the different states of an Command
there are these functions
startExecution
will issue a CommandResult with data: null error: null isExecuting : true -
toString(
) → String -
A string representation of this object.
inherited
-
toWidget(
{required Widget onResult(TResult? lastResult, TParam? param), Widget whileExecuting(TResult? lastResult, TParam? param)?, Widget onError(Object? error, TParam? param)?}) → Widget -
Returns a the result of one of three builders depending on the current state
of the Command. This function won't trigger a rebuild if the command changes states
so it should be used together with get_it_mixin, provider, flutter_hooks and the like.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited