testing library
Testing utilities for Juice blocs.
- juiceTest / runJuiceTest: declare a bloc test — build, seed, act, then assert on exactly what the bloc emitted (groups as widgets saw them), with the bloc closed before asserting and every use-case or stream-binding error reported. The default.
- BlocTester: an imperative recorder with assertion helpers.
import 'package:juice/testing.dart';
juiceTest<CounterBloc, CounterState>(
'increment emits the new count',
build: () => CounterBloc(),
act: (bloc) => bloc.send(IncrementEvent()),
expect: () => [isUpdatingStatus(state: const CounterState(count: 1))],
);
Classes
-
BlocTester<
TBloc extends JuiceBloc< TState> , TState extends BlocState> - A test utility class for testing Juice blocs.
-
JuiceEmission<
TState extends BlocState> - One status a bloc emitted during a juiceTest, with the rebuild groups it carried AT EMIT TIME — exactly what widgets' group filter saw for it.
Extensions
-
BlocTesterExtension
on JuiceBloc<
TState> - Extension to create a tester directly from a bloc.
Functions
-
isCancelingStatus(
{Object? state, Object? groups}) → Matcher - Matches a JuiceEmission whose status is a CancelingStatus.
-
isFailureStatus(
{Object? state, Object? groups, Object? error}) → Matcher -
Matches a JuiceEmission whose status is a FailureStatus;
errormatches the status's error. -
isUpdatingStatus(
{Object? state, Object? groups}) → Matcher - Matches a JuiceEmission whose status is an UpdatingStatus.
-
isWaitingStatus(
{Object? state, Object? groups}) → Matcher - Matches a JuiceEmission whose status is a WaitingStatus.
-
juiceTest<
TBloc extends JuiceBloc< (TState> , TState extends BlocState>String description, {required TBloc build(), TState seed()?, FutureOr< void> act(TBloc bloc)?, Duration? wait, int skip = 0, Object expect()?, Object errors()?, FutureOr<void> verify(TBloc bloc)?, bool allowInFlightAtClose = false, Object? tags, Object? skipTest}) → void - Declares a bloc test: build, (seed), act, then — with the bloc CLOSED — assert on exactly what it emitted.
-
runJuiceTest<
TBloc extends JuiceBloc< (TState> , TState extends BlocState>{required TBloc build(), TState seed()?, FutureOr< void> act(TBloc bloc)?, Duration? wait, int skip = 0, Object expect()?, Object errors()?, FutureOr<void> verify(TBloc bloc)?, bool allowInFlightAtClose = false}) → Future<List< JuiceEmission< >TState> > -
The body of juiceTest, callable directly (e.g. inside
testWidgets, or a test with custom setup). Returns the recorded emissions.