Skip to content

Commit

Permalink
provide clock in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
denrase committed Oct 22, 2024
1 parent f540ecb commit e5f628a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ class ScreenshotEventProcessor implements EventProcessor {
return event;
}

final now = DateTime.now();
// ignore: invalid_use_of_internal_member
final now = _options.clock();
final difference = _lastApplyCall?.difference(DateTime.now()).abs();
_lastApplyCall = now;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,13 @@ void main() {
await sut.apply(firstEvent, firstHint);
await sut.apply(secondEvent, secondHint);

// ignore: invalid_use_of_internal_member
fixture.options.clock = () => DateTime.fromMillisecondsSinceEpoch(0);
expect(firstHint.screenshot, isNotNull);

// ignore: invalid_use_of_internal_member
fixture.options.clock = () => DateTime.fromMillisecondsSinceEpoch(
sut.debounceDuration.inMilliseconds - 1);
expect(secondHint.screenshot, isNull);
});
});
Expand All @@ -223,8 +229,13 @@ void main() {
final secondEvent = SentryEvent(throwable: throwable);
final secondHint = Hint();

// ignore: invalid_use_of_internal_member
fixture.options.clock = () => DateTime.fromMillisecondsSinceEpoch(0);
await sut.apply(firstEvent, firstHint);
await Future<void>.delayed(sut.debounceDuration);

// ignore: invalid_use_of_internal_member
fixture.options.clock = () => DateTime.fromMillisecondsSinceEpoch(
sut.debounceDuration.inMilliseconds);
await sut.apply(secondEvent, secondHint);

expect(firstHint.screenshot, isNotNull);
Expand Down

0 comments on commit e5f628a

Please sign in to comment.