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

outdated

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

CI style license

rx_bloc_test #

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

rxBlocTest #

Testing a specific RxBloc state can be done easily with the rxBlocTest function. Besides a test description, it has two required parameters: build, which should return the testing RxBloc and state, which is a specific state inside the provided bloc.

Additionally, like in most cases, the state may return values which can be compared against other values. Here comes the expect parameter which takes a list of expected iterables and compares them with the ones from the state.

rxBlocTest<CounterBloc,int>(
  'Emits [] when created',
  build: () async => CounterBloc(), 
  state: (bloc) => bloc.states.count,
  expect: [],
)

There is an act parameter which is a callback executed after the bloc has been initialized. It should be used to add events to the block.

rxBlocTest<CounterBloc,int>(
  'Incrementing value',
  build: () async => CounterBloc(), 
  state: (bloc) => bloc.states.count,
  act: (bloc) async => bloc.events.increment(),
  expect: [1],
)

If you want, you can skip a custom amount of values that are emitted by the state by using the skip parameter. If no value is provided the default value of 1 is used, which will skip the initial value of the bloc state. The initial value can be included by setting the skip parameter to 0.

There is also a wait parameter which will wait for a given Duration to pass. This is useful especially when working with async operations.

rxBlocTest<DetailsBloc,String>(
  'Fetch third details data',
  build: () async => DetailsBloc(), 
  state: (bloc) => bloc.states.details,
  act: (bloc) async => bloc.events.fetch(),
  wait: Duration(milliseconds:100),
  skip: 3, // This will skip first two values + the initial value
  expect: ['Hello world'],
)
16
likes
0
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

License

unknown (LICENSE)

Dependencies

meta, quiver, rx_bloc, rxdart, test

More

Packages that depend on rx_bloc_test