Skip to content

Commit

Permalink
Refactor HandlerContext test: Improve event handling and context avai…
Browse files Browse the repository at this point in the history
…lability
  • Loading branch information
PlugFox committed Oct 16, 2024
1 parent b3e1eca commit 818e127
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions test/unit/handler_context_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ void main() => group('HandlerContext', () {
// After the normal event is called, the context should be available.
final value = math.Random().nextDouble();
HandlerContext? lastContext;
await controller.event(
controller.event(
meta: <String, Object?>{'double': value},
out: (ctx) => lastContext = ctx,
);
).ignore();
expect(controller.isProcessing, isTrue);
expect(lastContext, isNotNull);
await expectLater(lastContext!.done, completes);
// Event should be done by now.
expect(
lastContext,
allOf(
Expand Down Expand Up @@ -58,6 +62,16 @@ void main() => group('HandlerContext', () {
isA<Duration>(),
isNot(Duration.zero),
),
)
.having(
(ctx) => ctx.controller,
'controller',
same(controller),
)
.having(
(ctx) => ctx.isDone,
'isDone',
isTrue,
),
),
);
Expand Down Expand Up @@ -109,6 +123,7 @@ abstract base class _FakeControllerBase extends StateController<bool> {
}) =>
handle(
() async {
out?.call(Controller.context!);
final stopwatch = Stopwatch()..start();
try {
setState(false);
Expand Down

0 comments on commit 818e127

Please sign in to comment.