flutter-bloc-testing

Validate Bloc emitted state sequences with bloc_test and mocktail mocks.

Updated May 16, 2026
One-click install
npx skills add https://github.com/abdallhMoukdad/flutter-bloc-skills --skill flutter-bloc-testing
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: flutter-bloc-testing
Source: https://github.com/abdallhMoukdad/flutter-bloc-skills/tree/main/skills/flutter-bloc-testing
Command: npx skills add https://github.com/abdallhMoukdad/flutter-bloc-skills --skill flutter-bloc-testing

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Writing Bloc tests that confidently verify the exact emitted state sequence is difficult, especially when concurrency transformers, async handlers, and HydratedBloc persistence are involved.

Core Features & Use Cases

  • Deterministic Bloc testing with bloc_test: Build a fresh Bloc, drive events, and assert an ordered list of emitted states using a single declarative test harness.
  • mocktail-based repository mocking: Mock Repository dependencies without code generation, including registering fallback values for complex argument types.
  • Concurrency transformer verification: Use controlled timing with Completer to prove behavioral contracts for restartable/droppable/sequential-style handlers (e.g., cancellation of in-flight work).
  • HydratedBloc persistence round-trip tests: Replace HydratedBloc.storage with an in-memory Storage fake, clear per test, and assert rehydration after restart.

Quick Start

Use the flutter-bloc-testing skill to write bloc_test + mocktail unit tests for a Bloc event handler and include at least one case that proves the behavior of a concurrency transformer.

Frequently Asked Questions about flutter-bloc-testing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I test Bloc state sequences in Flutter with bloc_test?

Testing concurrency transformers in Bloc requires controlling async timing with Completer. This proves behavioral contracts for restartable, droppable, or sequential handlers by verifying cancellation of in-flight work during event processing.

Can I mock repository calls in Flutter Bloc tests without code generation?

Yes, you can mock repository calls in Flutter Bloc tests without code generation by using mocktail. You must register fallback values for complex argument types and use argument matching to stub repository calls for controlled test environments.

How do I test HydratedBloc persistence and rehydration in Flutter?

When testing HydratedBloc persistence, use an in-memory Storage fake to replace HydratedBloc.storage. Clearing this fake storage per test ensures isolated, deterministic rehydration round-trip verification after a simulated restart.

What is the best way to verify a Bloc concurrency transformer contract during testing?

The best way to verify a Bloc concurrency transformer contract is using controlled timing with Completer. This verifies behavioral contracts for restartable, droppable, or sequential handlers by proving the cancellation of in-flight work.

Why do my Bloc tests fail when asserting async event handler states?

Bloc tests fail when asserting async event handler states if you don't control async timing. You must use controlled timing with Completer and ordered stream expectations to verify the deterministic emitted state sequence for driven events.