I'm trying to create a reactive SharedPreferences utility but I'm stuck with this issue. This is my class
class SPUtil {
final _workoutsStreamController = StreamController<
Result<Iterable<PreferencesWorkout>, Exception>>.broadcast();
@override
Stream<Result<Iterable<PreferencesWorkout>, Exception>> getWorkouts() async* {
final prefs = await SharedPreferences.getInstance();
_workoutsStreamController.sink.add(success(_getStoredWorkouts(prefs)));
yield* _workoutsStreamController.stream;
}
}
And this is my test
test("getWorkouts SHOULD return empty list WHEN nothing is stored",
() async {
SharedPreferences.setMockInitialValues({});
final actual = await _sut.getWorkouts().first;
expect((actual as Success).value, []);
});
Whenever I run this test it loops for 30 seconds and it returns this error
dart:async _startMicrotaskLoop
TimeoutException after 0:00:30.000000: Test timed out after 30 seconds. See https://pub.dev/packages/test#timeouts
Everything works fine if I use this implementation instead
class SPUtil {
@override
Stream<Result<Iterable<PreferencesWorkout>, Exception>> getWorkouts() async* {
final prefs = await SharedPreferences.getInstance();
yield success(_getStoredWorkouts(prefs));
}
}
So I assume my test is correct. Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire