Hi, I have the problem that a Test that is used in the demo of rx_widgets longer works:
test('should filter after the user stops typing for 500ms', () async {
// Use FakeAsync from the Quiver package to simulate time
new FakeAsync().run((time) {
final service = new MockService();
final model = new HomePageModel(service);
when(service.getWeatherEntriesForCity(any))
.thenAnswer((_) => new Future.sync(() => <WeatherEntry>[]));
model.textChangedCommand('A');
time.elapse(new Duration(milliseconds: 1000));
verify(service.getWeatherEntriesForCity('A'));
});
});
I found out that the problem is that verify is called before service.getWeatherEntriesForCity
is called with "A" which happens with a delay of 500ms because the HomePageModel
uses rxdart's debounceTime()
// When the user starts typing
_textChangedCommand
// Wait for the user to stop typing for 500ms
.debounceTime( Duration(milliseconds: 500))
// Then call the updateWeatherCommand
.listen(_updateWeatherCommand);
I could see while debugging that service.getWeatherEntriesForCity('A')
is indeed called but after verify
.
If anynone wants to give it a shot I really would be grateful you can fine the repo here:
https://github.com/escamoteur/rx_widgets/blob/master/example/test/homepage_model_test.dart
Yeh, looks like
FakeAsync
is causing troubles again. It's a shame, really -- the only solution I can think of is to remove FakeAsync and use regularawaits
. The downside: The tests will take longer to run, but at least they work.