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

discontinued

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
43%
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

Documentation

Documentation

License

MIT (LICENSE)

Dependencies

cubit, meta, mockito, test

More

Packages that depend on cubit_test