velo_test library
Testing utilities for the Velo state management package.
This package provides helpful utilities and mock classes for testing applications that use Velo for state management.
Features
- Mock Velo classes for testing
- Test helpers for common testing scenarios
- Widget testing utilities
- State verification helpers
- veloTest function similar to blocTest
- Custom matchers for Velo testing
Usage
import 'package:velo_test/velo_test.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('CounterVelo', () {
veloTest<CounterVelo, int>(
'emits [1] when increment is called',
build: () => CounterVelo(),
act: (velo) => velo.increment(),
expect: () => [1],
);
veloTest<CounterVelo, int>(
'emits [1, 2, 3] when increment is called 3 times',
build: () => CounterVelo(),
act: (velo) async {
velo.increment();
velo.increment();
velo.increment();
},
expect: () => [1, 2, 3],
);
});
}
Classes
- CounterState
- A simple counter state for testing purposes.
- CounterVelo
- A test Velo implementation for counter functionality.
-
MockVelo<
T> -
A mock implementation of
Velofor testing purposes. - SimpleState
- A simple state class without Equatable for testing.
- SimpleVelo
- A simple test Velo implementation.
- VeloMatchers
- Custom matchers for Velo testing.
- VeloTestUtils
- Utility functions for Velo testing.
-
VeloTestWidget<
T extends Velo< S> , S> - Helper class for creating mock widgets that use Velo.
Extensions
- VeloWidgetTester on WidgetTester
- Extension methods for WidgetTester to simplify Velo widget testing.
Functions
-
buildText(
BuildContext context, CounterState state) → Widget - Helper function to build a text widget from counter state.
-
createTestWidget(
{required Widget child, CounterVelo? counterVelo, SimpleVelo? simpleVelo}) → Widget - Creates a test widget with the necessary providers.
-
createVeloBuilderTestWidget<
T extends Velo< (S> , S>{required T velo, required Widget builder(BuildContext, S)}) → Widget - Creates a test widget that wraps a VeloBuilder.
-
createVeloListenerTestWidget<
T extends Velo< (S> , S>{required T velo, required void listener(BuildContext, S), Widget? child}) → Widget - Creates a test widget that wraps a VeloListener.
-
emitsAnyOf<
S> (List< S> expectedStates) → Matcher - Matches when a Velo notifier emits any of the expected states.
-
emitsCount(
int expectedCount) → Matcher - Matches when a Velo notifier emits exactly the expected number of states.
-
emitsInOrder<
S> (List< S> expectedStates) → Matcher - Matches when a Velo notifier emits the expected states in order.
-
emitsWhere<
S> (bool predicate(S state)) → Matcher - Matches when a Velo notifier emits states that satisfy the given predicate.
-
hasState<
S> (S expectedState) → Matcher - Matches when a Velo notifier's current state equals the expected state.
-
pumpAndSettle(
WidgetTester tester, Widget widget) → Future< void> - Pumps a widget and waits for all animations and microtasks to complete.
-
veloTest<
V extends Velo< (S> , S>String description, {required V build(), S? seed, FutureOr< void> act(V velo)?, Duration? wait, int skip = 0, dynamic expect()?, dynamic errors()?, FutureOr<void> setUp()?, FutureOr<void> tearDown()?, FutureOr<void> verify(V velo)?, Map<String, dynamic> ? tags, Duration? timeout}) → void -
Tests a
Veloby runningactand asserting that the correct sequence of states are emitted. -
waitFor(
bool condition(), {Duration timeout = const Duration(seconds: 5), Duration interval = const Duration(milliseconds: 100)}) → Future< void> - Utility function to wait for a condition with a timeout.
-
waitForCondition(
bool condition(), {Duration timeout = const Duration(seconds: 5), Duration interval = const Duration(milliseconds: 100)}) → Future< void> - Waits for a specific condition to be true with a timeout.
Exceptions / Errors
- TimeoutException
- Exception thrown when a condition times out.