Recipes
Advance policy time deterministically
Test Debounce, Throttle, Rate Limit, and timestamps without sleeping.
v1.1.0Intermediateusecase_forge_test
Advance policy time deterministically
Inject TestUseCaseClock into the UseCase instead of waiting for wall-clock timers.
dart
final clock = TestUseCaseClock(DateTime.utc(2030));
final useCase = SearchUseCase(clock: clock);
final observer = UseCaseTestObserver<SearchState>(useCase);
useCase.add(const SearchCommand('dart'));
clock.advance(const Duration(milliseconds: 300));
await observer.waitForHistory(hasLength(1));
Pass the clock to the core constructor with super(initialState: ..., clock: clock). advance runs policy callbacks whose scheduled time has arrived and controls Entry timestamps. The test now names the exact policy trigger and does not depend on scheduler or machine speed.
Close the UseCase and cancel the observer in teardown. Advancing time does not automatically prove terminal completion; wait for the observable condition that the scenario requires.