Skip to content

testing AsyncValueObservation #1689

Answered by groue
yqiang asked this question in Q&A
Dec 19, 2024 · 2 comments · 2 replies
Discussion options

You must be logged in to vote

This approach works but feels clunky.

We have to wait for something. So maybe "clunky" refers to await MainActor.run {}. Indeed I'm not sure it guarantees with 100% certainty that the fresh values were notified and that you can proceed with assertions. And at some point in the future viewModel.observeData() could evolve and await for something else before observing the database, and break the tests.

How can I ensure the observation task starts and fetches the initial data before proceeding with assertions?

Testing async sequences is difficult because it is unclear when the iteration has started. There is a forum thread with a lot of discussions about this topic at Reliably testing cod…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@yqiang
Comment options

Comment options

You must be logged in to vote
1 reply
@yqiang
Comment options

Answer selected by yqiang
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants