I use MobX for state management in my Flutter app and my store has an init() method, that is used to populate the state with all the information that is needed on startup:
MyStore {
...
bool _initialized = false;
...
void init() {
if (!_initialized) {
fetchInfo();
_initialized = true;
}
}
...
@action
void fetchInfo() { alter observables of store }
}
As I didn't commit to TDD, I'm now in the position to write unit tests after the implementation and I have no idea how to test that e.g. init calls fetchInfo and only really runs once.
If fetchInfo was in another class, I could mock it, but as it alters observables of MyStore, I don't think it could be extracted.
Does anyone have an idea on how to test this or how to refactor this? Thanks