bloc_test
10.0.0, released 2 years ago by bloclibrary.dev
A testing library that makes it easy to test blocs and cubits.
WASM-readyQuiet but busy
What it does
Provides utilities like blocTest and whenListen to simplify testing state changes, emitted states, and async operations in blocs and cubits. It handles stream closing and expectations sequencing automatically.
AI-written summary of version 10.0.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You are writing unit tests for blocs or cubits
- You need to verify emitted states in order after an action
- You need to stub state streams using whenListen
Skip it when
- You are not using the bloc state management package
- You are testing UI widgets rather than business logic
Strengths
- Simplifies asynchronous bloc testing with clear syntax
- Provides built-in support for seeding states, skipping events, and waiting on async operations
- Integrates seamlessly with package:test and mocktail
Weaknesses
- Strictly tied to the bloc ecosystem
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 5
not documented
group('CounterBloc', () => {
blocTest(
'emits [1] when CounterIncrementPressed is added',
build: () => CounterBloc(),
act: (bloc) => bloc.add(CounterIncrementPressed()),
expect: () => [1],
);
});Alternatives
Packages that do the same job and could replace bloc_test.
Works with
Packages commonly used together with bloc_test: ones it builds on, ones built on it, and its own family.
- testbloc_test depends on itA full featured library for writing and running Dart tests across platforms.
- mocktailbloc_test depends on itDart mock library with null safety support and no manual mocks or code generation.
- blocbloc_test depends on itA Dart library for implementing the BLoC pattern with Cubits and Blocs.
- diff_match_patchbloc_test depends on itDart library implementing diff, match and patch algorithms for plain text.
- flutter_blocSame familyFlutter widgets to easily integrate blocs and cubits for state management.
- bloc_concurrencySame familyCustom event transformers for the bloc state management package.
- hydrated_blocSame familyAutomatically persists and restores bloc and cubit states.
- bloc_lintSame familyOfficial lint rules for development when using the bloc state management library.