runAjwahTest<State> function

  1. @visibleForTesting
Future<void> runAjwahTest<State>(
  1. String description, {
  2. required Stream<State> build(),
  3. dynamic act()?,
  4. Duration? wait,
  5. int skip = 0,
  6. Iterable? expect,
  7. dynamic verify(
    1. List<State> models
    )?,
  8. Iterable? errors,
  9. Function? tearDown,
  10. dynamic log(
    1. List<State> models
    )?,
})

Internal ajwahTest runner which is only visible for testing. This should never be used directly -- please use ajwahTest instead.

Implementation

@visibleForTesting
Future<void> runAjwahTest<State>(
  String description, {
  required Stream<State> Function() build,
  Function()? act,
  Duration? wait,
  int skip = 0,
  Iterable? expect,
  Function(List<State> models)? verify,
  Iterable? errors,
  Function? tearDown,
  Function(List<State> models)? log,
}) async {
  final unhandledErrors = <Object>[];
  await runZonedGuarded(
    () async {
      final states = <State>[];
      final stream = build();
      final subscription = stream.skip(skip).listen(states.add);
      await act?.call();
      if (wait != null) await Future<void>.delayed(wait);
      await Future<void>.delayed(Duration.zero);
      await log?.call(states);
      if (expect != null) test.expect(states, expect);
      await subscription.cancel();
      await verify?.call(states);
      await tearDown?.call();
    },
    (Object error, _) {
      unhandledErrors.add(error);
    },
  );
  if (errors != null) test.expect(unhandledErrors, errors);
}