Hi,
I'm face a problem that I don't know how to solve it. I have two observables and when one received a value, the other receive a value from a service. That means it all are asynchronous and when I attempt to test it, It fails.
So. I need a way to test observables with reactions.
Here a sample code to explain better this problem.
If I test the reaction without a Future call, in other words, if a directly change the value of observable inside de reaction, I can test the reaction.
And the test pass too if I put a delay of Duration.zero before the expect.
There's something that we should do to test reactions that call asynchronous a test that I'm missing?
Would asyncWhen help somehow?
Would
asyncWhenhelp somehow?
In one case when there's the need of when I think so, but in this case, the reaction needs be triggered in every change of the observable.
Also I think that asyncWhen auto-dispose like when after effect runs.
@pavanpodila Can you help us? Thank you! =)
@TercyoStorck take a look at the PR I submitted back to your repo here where asyncWhen is used in the code for testing not within the actual logic of your app
Another thing to add is to not block your tests from stalling indefinitely (?), when awaiting a reaction that fails to trigger (e.g. when you have a bug in your code) is to set a timeout on the Future returned by asyncWhen
Great points Michael. You should definitely write a testing guide for the site!
Good idea but not sure when and if I can get around to that the at the moment. Perhaps let's create an issue for that to open that up for others to contribute as well. I'm going to close this one as @TercyoStorck's should be resolved now
@TercyoStorck take a look at the PR I submitted back to your repo here where
asyncWhenis used in the code for testing not within the actual logic of your app
It worked very well. Thanks!
Most helpful comment
Great points Michael. You should definitely write a testing guide for the site!