Skip to content

Commit e5f628a

Browse files
committed
provide clock in tests
1 parent f540ecb commit e5f628a

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

flutter/lib/src/event_processor/screenshot_event_processor.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ class ScreenshotEventProcessor implements EventProcessor {
3939
return event;
4040
}
4141

42-
final now = DateTime.now();
42+
// ignore: invalid_use_of_internal_member
43+
final now = _options.clock();
4344
final difference = _lastApplyCall?.difference(DateTime.now()).abs();
4445
_lastApplyCall = now;
4546

flutter/test/event_processor/screenshot_event_processor_test.dart

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,13 @@ void main() {
201201
await sut.apply(firstEvent, firstHint);
202202
await sut.apply(secondEvent, secondHint);
203203

204+
// ignore: invalid_use_of_internal_member
205+
fixture.options.clock = () => DateTime.fromMillisecondsSinceEpoch(0);
204206
expect(firstHint.screenshot, isNotNull);
207+
208+
// ignore: invalid_use_of_internal_member
209+
fixture.options.clock = () => DateTime.fromMillisecondsSinceEpoch(
210+
sut.debounceDuration.inMilliseconds - 1);
205211
expect(secondHint.screenshot, isNull);
206212
});
207213
});
@@ -223,8 +229,13 @@ void main() {
223229
final secondEvent = SentryEvent(throwable: throwable);
224230
final secondHint = Hint();
225231

232+
// ignore: invalid_use_of_internal_member
233+
fixture.options.clock = () => DateTime.fromMillisecondsSinceEpoch(0);
226234
await sut.apply(firstEvent, firstHint);
227-
await Future<void>.delayed(sut.debounceDuration);
235+
236+
// ignore: invalid_use_of_internal_member
237+
fixture.options.clock = () => DateTime.fromMillisecondsSinceEpoch(
238+
sut.debounceDuration.inMilliseconds);
228239
await sut.apply(secondEvent, secondHint);
229240

230241
expect(firstHint.screenshot, isNotNull);

0 commit comments

Comments
 (0)