I have a library which has many async parts to it, and testing a specific part of it can sometimes mean waiting for n asynchronous processes to complete before the test is available to actually be run. I have been using this method to achieve my purposes:
void expectAsyncWithReadyCheckAndTimeout(bool readyCheck(), int timeout, void expect()){
DateTime start = new DateTime.now();
Duration limit = new Duration(seconds: timeout);
var inner;
inner = (){
if(readyCheck()){
expect();
}else if(new DateTime.now().subtract(limit).isAfter(start)){
throw 'async test timed out';
}else{
Timer.run(expectAsync(inner));
}
};
inner();
}
this basically keeps running until either the test is ready to be run or until some specified timeout expires, is there a way of achieving this or something similar directly with the dart unittest library?