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

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 implements RxBlocTypeBase {
  final _loadingCount = BehaviorSubject<int>.seeded(0);

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

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

  @override
  void dispose() {
    _loadingCount.close();
    return super.dispose();
  }
}
16
likes
140
pub points
50%
popularity

Publisher

verified publisherprimeholding.com

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

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

fake_async, meta, rx_bloc, rxdart, test

More

Packages that depend on rx_bloc_test