bloc_testmate 1.0.3 copy "bloc_testmate: ^1.0.3" to clipboard
bloc_testmate: ^1.0.3 copied to clipboard

Package that streamlines testing for BLoCs. tiny test-oriented DI container, not boilerplate.Supports data-driven tests, helpful matchers, and async-friendly waits.

example/bloc_testmate_example.dart

import 'package:bloc_testmate/bloc_testmate.dart';

import 'login_bloc.dart';

/// Import your example bloc (you can copy the one in test/login_bloc.dart)

void main() {
  final mate = BlocTestMate<LoginBloc, LoginState>()
      .arrange((get) {
        // Register a fake AuthRepo that returns success
        get.register<AuthRepo>(FakeAuthRepo(success: true));
      })
      .factory((get) => LoginBloc(get<AuthRepo>()));

  // Simple example: login succeeds
  mate.scenario(
    'login ok',
    given: () => [CredentialsEntered('a@a.com', '1234')],
    when: (bloc) => bloc.add(SubmitPressed()),
    wait: const Duration(milliseconds: 20),
    expectStates: [isA<LoginLoading>(), isA<LoginSuccess>()],
  );

  // Simple example: login fails
  mate.scenario(
    'login falla',
    arrange: (get) =>
        get.register<AuthRepo>(FakeAuthRepo(success: false), override: true),
    given: () => [CredentialsEntered('a@a.com', 'bad')],
    when: (bloc) => bloc.add(SubmitPressed()),
    wait: const Duration(milliseconds: 20),
    expectStates: [isA<LoginLoading>(), isA<LoginError>()],
  );
}
2
likes
0
points
383
downloads

Publisher

unverified uploader

Weekly Downloads

Package that streamlines testing for BLoCs. tiny test-oriented DI container, not boilerplate.Supports data-driven tests, helpful matchers, and async-friendly waits.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

analyzer, args, bloc, bloc_test, glob, path, test, yaml

More

Packages that depend on bloc_testmate