Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support time manipulation in bloc_test with clock/fakeAsync #4048

Closed
fabianbrandscheid opened this issue Jan 22, 2024 · 2 comments · May be fixed by #3796
Closed

feat: Support time manipulation in bloc_test with clock/fakeAsync #4048

fabianbrandscheid opened this issue Jan 22, 2024 · 2 comments · May be fixed by #3796

Comments

@fabianbrandscheid
Copy link

Description

I have a block which executes a network access via a usecase. It waits 20 seconds for a response before the future throws a timeout and a FailureState is emitted.
I wanted to use the Clock&FakeAsync package to avoid having to wait 20 seconds in the BlocTest in the event of an error.
For "manual" Bloc tests, the entire test content can simply be wrapped:

 test("Future.timeout() throws an error once the timeout is up", () async {
    // Act

    // Assert
    unawaited(fakeAsync((async) async {
      await setUpGetSyncSntity(duration: const Duration(milliseconds: 22));

      final bloc = getBloc();

      bloc.add(SyncStartEvent());

      async.elapse(Duration(seconds: 21));

      await expectLater(
          bloc.stream,
          emitsInOrder([
            const State1(),
            const TimeOutState(),
          ]));

      // Clean up
      await bloc.close();
    }));
  });

This advances the time by 21 seconds and simulates a timeout without actually having to wait 21 seconds.

Desired Solution

Could this option also be supported for BlocTests?
I suspect that the complete content of testBloc would have to be wrapped internally with FakeAsync and the time would have to be fast-forwarded after the call of act

@tenhobi
Copy link
Collaborator

tenhobi commented Jan 22, 2024

Hi, there is already opened PR #3796

@fabianbrandscheid
Copy link
Author

Oh thanks, I will close my issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants