|
โก bloc_signals_test"With the rigor of BLoC and the flex and speed of Signals"
Declarative unit testing utilities for bloc_signals
and |
bloc_signals_test provides blocSignalTest, a declarative helper tailored specifically for synchronous reactive signal state propagation, state de-duplication, and observer isolation.
๐ Ecosystem Packages
The BlocSignal monorepo consists of 10 modular packages:
โก Key Features
- ๐ฏ Declarative Assertions: Verify emitted states in exact order using
expect. - โฑ๏ธ Async Support: Await asynchronous event handlers or timers using
wait. - โญ๏ธ State Skipping: Skip initial emissions using
skip. - ๐จ Error Testing: Verify exceptions caught in
onErrorusingerrors. - ๐งน Automatic Cleanup: Guarantees observer restoration and
bloc.close()post-test.
๐ Getting Started
Add bloc_signals_test to your pubspec.yaml:
dev_dependencies:
bloc_signals_test: ^0.1.0
test: ^1.24.0
๐ก Quick Examples
1. Cubit Unit Test (blocSignalTest)
import 'package:bloc_signals_test/bloc_signals_test.dart';
import 'package:test/test.dart';
void main() {
group('CounterCubit', () {
blocSignalTest<CounterCubit, int>(
'emits [1] when increment is called',
build: CounterCubit.new,
act: (cubit) => cubit.increment(),
expect: () => [1],
);
});
}
2. Async Event Bloc Test (wait & errors)
blocSignalTest<DataBloc, DataState>(
'emits [DataLoading, DataLoaded] when FetchData succeeds',
build: () => DataBloc(repository: mockRepo),
act: (bloc) => bloc.add(FetchData()),
wait: const Duration(milliseconds: 100),
expect: () => [
const DataLoading(),
const DataLoaded('sample_data'),
],
);
๐ค AI Coding Assistant Skill
This package is supported by an official pre-packaged AI Coding Skill representing unit testing patterns, observer isolation, and synchronous assertion guidelines for BlocSignal.
If you develop with AI coding assistants (such as Claude Code, Antigravity, Gemini, Cursor, or Codex), you can load the bloc-signals skill bundle to guide your assistant's code generation and analysis.
๐ License
MIT License. See LICENSE for details.