Skip to content

Commit

Permalink
test: Add test for evaluating future-based callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
pongloongyeat committed Feb 7, 2023
1 parent 4ef8976 commit f51fa61
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/notification_dispatcher_test.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:async';

import 'package:equatable/equatable.dart';
import 'package:notification_dispatcher/src/notification_dispatcher.dart';
import 'package:test/test.dart';
Expand Down Expand Up @@ -222,5 +224,29 @@ void main() {
expect(callCount, 1);
MockNotificationDispatcher.instance.clearAll();
});

test('calls futures on post', () async {
var callCount = 0;
const delay = Duration(milliseconds: 100);

MockNotificationDispatcher.instance.addObserver(
instance,
name: observerName,
callback: (_) async => Future.delayed(
delay,
() => callCount++,
),
);

unawaited(MockNotificationDispatcher.instance.post(name: observerName));
expect(callCount, 0);
await Future.delayed(delay);
expect(callCount, 1);

await MockNotificationDispatcher.instance.post(name: observerName);
expect(callCount, 2);

MockNotificationDispatcher.instance.clearAll();
});
});
}

0 comments on commit f51fa61

Please sign in to comment.