Closed brianegan closed 5 years ago
That's a good suggestion @brianegan. I am very open to having a matcher package, specifically for mobx-focused tests.
If you are writing logic tests for MobX, you can rely on when() or asyncWhen() as well.
Closing this for now.
Just a passing thought, but I was wondering if
mobx
might be amenable to amobx_test
package that provides custom matchers for observables? I'm taking inspiration from Stream Matchers, here: https://pub.dartlang.org/packages/test#stream-matchersFor example, say you want to verify that an observable emits two states in response to an action, it might be coo to have something like (pseudocode warning, might not be 100% right, but to get the idea across!):
This can be really handy when it comes to testing logic, especially if you want the Observable to be in an expected state in response to an API or async call. An example of test where I use this for the bloc pattern and really like the approach:
https://github.com/brianegan/github_search_angular_flutter/blob/master/github_search_common/test/ui/search_bloc_test.dart
Potential matchers, using
notifies
in place ofemit
, but naming is just for demonstration and open to feedback:Update, I think this could help your own tests as well! E.g. this kinda stuff here:
We used to do this EXACT same thing in RxDart before StreamMatchers were available, and they really clean up the testing code.