useCaseTest<U extends UseCase<Entity>, M extends DomainModel> function

  1. @isTest
void useCaseTest<U extends UseCase<Entity>, M extends DomainModel>(
  1. String description, {
  2. required ProvidersContext context,
  3. required U build(
    1. Ref<Object?>
    ),
  4. required FutureOr<void> execute(
    1. U
    ),
  5. FutureOr<void> setup(
    1. UseCaseProvider<Entity, UseCase<Entity>>
    )?,
  6. Iterable expect()?,
  7. FutureOr<void> verify(
    1. U
    )?,
})

Implementation

@isTest
void useCaseTest<U extends UseCase, M extends DomainModel>(
  String description, {
  required ProvidersContext context,
  required U Function(Ref) build,
  required FutureOr<void> Function(U) execute,
  FutureOr<void> Function(UseCaseProvider)? setup,
  Iterable<dynamic> Function()? expect,
  FutureOr<void> Function(U)? verify,
}) {
  test(
    description,
    () async {
      final provider = UseCaseProvider(build);
      await setup?.call(provider);

      final useCase = provider.getUseCaseFromContext(context);

      Future<void>? expectation;
      if (expect != null) {
        expectation = expectLater(
          useCase.stream.map((_) => useCase.getDomainModel<M>()),
          emitsInOrder(expect()),
        );
      }

      await execute(useCase);
      await expectation;

      await verify?.call(useCase);
    },
  );
}