Skip to content

Best practices for async testing #11

Answered by cybrox
cybrox asked this question in Q&A
Discussion options

You must be logged in to vote

In case anyone finds this helpful, I since figured out what happened...

I was using State.onStream for multiple states in my state machine and I used the following code in test files main() function:

  mockAccountService = MockAccountService();

  StreamController<NativeEvent>? accountEvents;

  setUp(() {
    reset(mockAccountService);

    accountEvents = StreamController<NativeEvent>(sync: true);
    when(() => mockAccountService.events).thenAnswer((_) => accountEvents!.stream);
  });

  tearDown(() {
    accountEvents!.close();
    accountEvents = null;
  });

  test("...", () {
    // can now simply use accountEvents!.add(); to simulate inputs via stream
  });

Now, since accountEvents

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by renggli
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #9 on December 29, 2021 11:33.