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

thenAnswerInOrder support #704

Open
ANDREYDEN opened this issue Oct 17, 2023 · 0 comments
Open

thenAnswerInOrder support #704

ANDREYDEN opened this issue Oct 17, 2023 · 0 comments

Comments

@ANDREYDEN
Copy link

ANDREYDEN commented Oct 17, 2023

Currently, thenReturnInOrder does not accept Futures or Streams (similarly to thenReturn).

I would like to be able to write the following code:

when(methodReturningStream).thenAnswerInOrder([
    Stream.fromIterable([1, 2, 3]),
    Stream.fromIterable([4, 5, 6]),
]);

I've looked into the code and found that thenReturnInOrder internally actually calls thenAnswer, which probably means that the call to _throwIfInvalid is not needed.

This is similar to #260, but for Futures and Streams.

Edit: found this workaround, but it is still not trivial to figure this out when first coming to the package. I suppose an alternative to thenAnswerInOrder could be storing some state on the Invocation object:

when(methodReturningStream).thenAnswer((invocation) => [
    Stream.fromIterable([1, 2, 3]),
    Stream.fromIterable([4, 5, 6]),
][invocation.numberOfTimesCalled]);

I'm quite new to this library, so please correct me if anything I'm saying is wrong.

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

No branches or pull requests

1 participant