bloc_presentation_test 0.2.0 copy "bloc_presentation_test: ^0.2.0" to clipboard
bloc_presentation_test: ^0.2.0 copied to clipboard

A testing library for Blocs/Cubits which mixin BlocPresentationMixin. To be used with bloc_presentation package.

example/lib/main.dart

import 'dart:async';

import 'package:bloc/bloc.dart';
import 'package:bloc_presentation/bloc_presentation.dart';
import 'package:bloc_presentation_test/bloc_presentation_test.dart';
import 'package:bloc_test/bloc_test.dart';
import 'package:test/test.dart';

class CounterCubit extends Cubit<int> with BlocPresentationMixin {
  CounterCubit() : super(0);
}

class CounterPresentationEvent extends BlocPresentationEvent {
  const CounterPresentationEvent();
}

class MockCounterPresentationCubit extends MockPresentationCubit<int>
    implements CounterCubit {}

class MockCounterCubit extends MockCubit<int> implements CounterCubit {}

void main() {
  mainMockPresentationCubit();
  mainWhenListenPresentation();
}

void mainMockPresentationCubit() {
  late MockCounterPresentationCubit mockCubit;

  setUp(() {
    mockCubit = MockCounterPresentationCubit();
  });

  tearDown(() {
    mockCubit.close();
  });

  test(
    'presentation stream emits events properly',
    () async {
      mockCubit.emitMockPresentation(const CounterPresentationEvent());

      await expectLater(
        mockCubit.presentation,
        emitsInOrder(
          <Matcher>[
            equals(const CounterPresentationEvent()),
          ],
        ),
      );
    },
  );
}

void mainWhenListenPresentation() {
  late MockCounterCubit mockCubit;
  late StreamController<CounterPresentationEvent> controller;

  setUp(() {
    mockCubit = MockCounterCubit();
    controller = whenListenPresentation(
      mockCubit,
      initialEvents: [const CounterPresentationEvent()],
    );
  });

  tearDown(() {
    mockCubit.close();
  });

  test(
    'presentation stream emits events properly',
    () async {
      controller.add(const CounterPresentationEvent());

      await expectLater(
        mockCubit.presentation,
        emitsInOrder(
          <Matcher>[
            equals(const CounterPresentationEvent()),
            equals(const CounterPresentationEvent()),
          ],
        ),
      );
    },
  );
}
11
likes
0
points
7.15k
downloads

Publisher

verified publisherleancode.co

Weekly Downloads

A testing library for Blocs/Cubits which mixin BlocPresentationMixin. To be used with bloc_presentation package.

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

bloc, bloc_presentation, flutter, mocktail

More

Packages that depend on bloc_presentation_test