At the moment, it is not possible to reset the state of all Ref from lite_ref_core objects between tests if they are declared as global variables.
Switching entirely to ScopedRef is challenging because defining asynchronous dependencies requires using overrides during initialization, which is not very convenient.
As an alternative, Refs can be stored in a container and reinitialized between tests.
Are there any other options or ideas for the API on how this can be improved?
import 'package:flutter_test/flutter_test.dart';
import 'package:lite_ref/lite_ref.dart';
class Bar {
Bar(this.value);
final int value;
}
final foo = Ref.singleton(() => 1);
final bar = Ref.singleton(() {
return Bar(foo.instance);
});
void main() {
test('without override', () {
expect(foo.instance, 1);
expect(bar.instance.value, 1);
});
test('with override', () {
foo.overrideWith(() => 2);
expect((foo.instance, bar.instance.value), (2, 2));
});
test('without override after override', () {
expect((foo.instance, bar.instance.value), (1, 1));
});
test('override after override', () {
foo.overrideWith(() => 3);
expect((foo.instance, bar.instance.value), (3, 3));
});
}
At the moment, it is not possible to reset the state of all
Ref
fromlite_ref_core
objects between tests if they are declared as global variables.Switching entirely to
ScopedRef
is challenging because defining asynchronous dependencies requires using overrides during initialization, which is not very convenient.As an alternative,
Ref
s can be stored in a container and reinitialized between tests.Are there any other options or ideas for the API on how this can be improved?