Skip to content

Poorgramer-Zack/dart-expert-skills / skills/bloc-signals

bloc-signals

Verified

Implement, review, test, and migrate Dart and Flutter code that uses BlocSignal (bloc_signals, bloc_signals_flutter, bloc_signals_test), the BLoC-style API built on signals. Use this when the code imports package:bloc_signals, extends BlocSignal or CubitSignal, uses BlocSignalProvider, BlocSignalBuilder, BlocSignalListener, or context.select, or when the user asks how BlocSignal differs from flutter_bloc or wants to move from BLoC to synchronous signal-based state.

FileKindSize
SKILL.mdskill md3.5 KB
references/core.mdmarkdown3.0 KB
references/flutter.mdmarkdown3.0 KB
references/migration-from-bloc.mdmarkdown3.5 KB
references/testing.mdmarkdown2.2 KB

references/testing.md

View on GitHub
# Testing BlocSignal

Verified against `bloc_signals_test` 1.0.3. The sample below passed with `flutter test`.

## Declarative tests with `blocSignalTest`

```dart
import 'package:bloc_signals_test/bloc_signals_test.dart';
import 'package:test/test.dart';

void main() {
  blocSignalTest<CounterBloc, int>(
    'emits 1 after Increment',
    build: () => CounterBloc(),
    act: (bloc) => bloc.add(Increment()),
    expect: () => [1],
  );
}
```

- `blocSignalTest<B, State>` takes `build`, `act`, `expect`, and optionally `wait:` for asynchronous handlers, plus `tags:`.
- Because handlers are synchronous, most tests need no `wait`.

## Direct assertions

```dart
test('synchronous emit updates stateValue immediately', () {
  final bloc = CounterBloc();
  bloc.add(Increment());
  expect(bloc.stateValue, 1);
  bloc.close();
});
```

Close every bloc you create in tests, including on failure (use `addTearDown(bloc.close)`).

## Asynchronous handlers

- Use `wait:` in `blocSignalTest`, or await the handler's future through a `Completer`, to observe results of `async` event handlers.
- `add` does not return the handler's future. Errors from async handlers are reported to the observer, and `close` does not cancel them.

## Widget tests

```dart
testWidgets('BlocSignalProvider + BlocSignalBuilder rebuilds on add', (tester) async {
  await tester.pumpWidget(
    MaterialApp(
      home: BlocSignalProvider(
        create: (_) => CounterBloc(),
        child: Builder(
          builder: (context) => Scaffold(
            body: BlocSignalBuilder<CounterBloc, int>(
              builder: (context, count) => Text('count=$count'),
            ),
            floatingActionButton: FloatingActionButton(
              onPressed: () => context.read<CounterBloc>().add(Increment()),
              child: const Icon(Icons.add),
            ),
          ),
        ),
      ),
    ),
  );
  expect(find.text('count=0'), findsOneWidget);
  await tester.tap(find.byType(FloatingActionButton));
  await tester.pump();
  expect(find.text('count=1'), findsOneWidget);
});
```

To replace a bloc in a widget test, use `BlocSignalProvider.value` with a fake instance you control.

## Commands

```bash
flutter test
flutter analyze
```
finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 323kUpdated Claude CodeCodexVerifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 323kUpdated Claude CodeCodexVerifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 323kUpdated Claude CodeCodexVerifiedInstall
skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.Stars: 198kUpdated Claude CodeCodexVerifiedInstall