useCaseTest<U extends UseCase<Entity>, M extends DomainModel> function
void
useCaseTest<
U extends UseCase<Entity>, M extends DomainModel>( - String description, {
- required ProvidersContext context,
- required U build(
- Ref<Object?>
),
- required FutureOr<void> execute(
- U
),
- FutureOr<void> setup(
- UseCaseProvider<Entity, UseCase<Entity>>
)?,
- Iterable expect()?,
- FutureOr<void> verify(
- 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);
},
);
}