cubit_test 0.1.0 copy "cubit_test: ^0.1.0" to clipboard
cubit_test: ^0.1.0 copied to clipboard

discontinuedreplaced by: bloc_test
outdated

A testing library built to make testing cubits easy. Built to be used with the cubit and bloc state management packages.

example/main.dart

import 'dart:async';

import 'package:cubit/cubit.dart';
import 'package:cubit_test/cubit_test.dart';
import 'package:test/test.dart';

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

  void increment() => emit(state + 1);
}

// Mock Cubit
class MockCounterCubit extends MockCubit<int> implements CounterCubit {}

void main() {
  group('whenListen', () {
    test("Let's mock the CounterCubit's stream!", () {
      // Create mock CounterCubit instance.
      final counterCubit = MockCounterCubit();

      // Stub the listen with a fake Stream.
      whenListen<CounterCubit, int>(
        counterCubit,
        Stream.fromIterable([0, 1, 2, 3]),
      );

      // Expect that the CounterCubit instance emits the stubbed states.
      expectLater(counterCubit, emitsInOrder(<int>[0, 1, 2, 3]));
    });
  });

  group('cubitTest', () {
    cubitTest<CounterCubit, int>(
      'emits [] when nothing is called',
      build: () async => CounterCubit(),
      expect: <int>[],
    );

    cubitTest<CounterCubit, int>(
      'emits [1] when increment is called',
      build: () async => CounterCubit(),
      act: (cubit) async => cubit.increment(),
      expect: <int>[1],
    );
  });
}
2
likes
40
pub points
34%
popularity

Publisher

verified publisherbloc-dev.com

A testing library built to make testing cubits easy. Built to be used with the cubit and bloc state management packages.

Repository (GitHub)
View/report issues
Contributing

License

MIT (license)

Dependencies

cubit, meta, mockito, test

More

Packages that depend on cubit_test