rx_bloc_test 1.0.1 copy "rx_bloc_test: ^1.0.1" to clipboard
rx_bloc_test: ^1.0.1 copied to clipboard

outdated

A Flutter package with the goal to enable testing rxBlocs from the FlutterRxBloc package with ease.

example/main.dart

import 'package:rx_bloc/rx_bloc.dart';
import 'package:rx_bloc_test/rx_bloc_test.dart';
import 'package:rxdart/rxdart.dart';
import 'package:test/test.dart';

void main() {
  group('CounterBloc tests', () {
    rxBlocTest<CounterBloc, int>(
      'Basic rxBlocTest',
      build: () async => CounterBloc(),
      state: (bloc) => bloc.count,
      expect: <int>[0],
    );

    rxBlocTest<CounterBloc, int>(
      'Executing action',
      build: () async => CounterBloc(),
      state: (bloc) => bloc.count,
      act: (bloc) async => bloc.increase(),
      expect: <int>[0, 1],
    );

    rxBlocTest<CounterBloc, int>(
      'Skipping results (skips 0 and 1)',
      build: () async => CounterBloc(),
      state: (bloc) => bloc.count,
      act: (bloc) async {
        bloc..decrease()..decrease();
      },
      skip: 2,
      expect: <int>[-2],
    );
  });
}

class CounterBloc extends RxBlocBase {
  final _loadingCount = BehaviorSubject<int>.seeded(0);

  Stream<int> get count => _loadingCount.stream;

  void increase() => ++_loadingCount.value;
  void decrease() => --_loadingCount.value;

  @override
  void dispose() {
    _loadingCount.close();
    return super.dispose();
  }
}
17
likes
40
points
202
downloads

Publisher

verified publisherprimeholding.com

Weekly Downloads

A Flutter package with the goal to enable testing rxBlocs from the FlutterRxBloc package with ease.

Homepage
Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

meta, quiver, rx_bloc, rxdart, test

More

Packages that depend on rx_bloc_test