halkyon/packages/halkyon_app/test/password/bloc/states.dart

28 lines
888 B
Dart
Raw Normal View History

import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:halkyon_app/halkyon_app.dart';
/// The states [cubit] emits while [step] runs, in order.
Future<List<S>> statesOf<S>(
BlocBase<S> cubit,
Future<void> Function() step,
) async {
final states = <S>[];
final listening = cubit.stream.listen(states.add);
await step();
// A cubit's stream hands its states on in a microtask.
await Future<void>.delayed(Duration.zero);
await listening.cancel();
return states;
}
/// The states [cubit] emits as [step] (not awaited: it emits at once).
Future<List<S>> statesNow<S>(BlocBase<S> cubit, void Function() step) =>
statesOf(cubit, () async => step());
/// A refusal of [problem].
Matcher refusedAs(PasswordProblem problem) => isA<PasswordFailed>().having(
(failed) => failed.problem,
'problem',
problem,
);