diff --git a/packages/netglade_utils/CHANGELOG.md b/packages/netglade_utils/CHANGELOG.md index a91f1b3..12f79f9 100644 --- a/packages/netglade_utils/CHANGELOG.md +++ b/packages/netglade_utils/CHANGELOG.md @@ -1,5 +1,7 @@ ## Unreleased - Require Dart SDK 3.8.0 or later. +- Add `verifyCalledOnceAndNoMoreInteractions` +- Add shortcut calls for stubbing When with Option result. ## 2.5.0 - Dependencies update. diff --git a/packages/netglade_utils/lib/src/testing/mock_extensions.dart b/packages/netglade_utils/lib/src/testing/mock_extensions.dart index dc2aa06..3dd8156 100644 --- a/packages/netglade_utils/lib/src/testing/mock_extensions.dart +++ b/packages/netglade_utils/lib/src/testing/mock_extensions.dart @@ -27,20 +27,37 @@ extension VerificationResultEx on VerificationResult { void calledOnce() => called(1); } +/// Verifies that the given mock was called exactly once with the provided function. +/// +/// Also verifies that no other interactions with the mock occurred. +// ignore: prefer-static-class, prefer-typedefs-for-callbacks, avoid-dynamic, keep it. +void verifyCalledOnceAndNoMoreInteractions(dynamic mock, T Function() verifyCall) { + verify(verifyCall).calledOnce(); + verifyNoMoreInteractions(mock); +} + extension SuccessAnswer on When>> { void thenAnswerWithSuccess(T value) => thenAnswer((_) async => Success(value)); + + void thenAnswerWithError(E error) => thenAnswer((_) async => Error(error)); } extension SuccessAnswerOr on When>> { void thenAnswerWithSuccess(T value) => thenAnswer((_) => Success(value)); + + void thenAnswerWithError(E error) => thenAnswer((_) => Error(error)); } -extension ErrorAnswer on When>> { - void thenAnswerWithError(E error) => thenAnswer((_) async => Error(error)); +extension OptionAnswer on When>> { + void thenAnswerWithNone() => thenAnswer((_) async => const None()); + + void thenAnswerWithSome(T value) => thenAnswer((_) async => Some(value)); } -extension ErrorAnswerOr on When>> { - void thenAnswerWithError(E error) => thenAnswer((_) => Error(error)); +extension OptionAnswerOr on When>> { + void thenAnswerWithNone() => thenAnswer((_) async => const None()); + + void thenAnswerWithSome(T value) => thenAnswer((_) async => Some(value)); } extension StreamSubscriptionAnswer on When> {