Open
Description
To keep #109 alive, related to #36, supabase/supabase-dart#12.
Any serious project needs unit testing around components using Supabase.
In my particular case, I have a provider that fetches data with Supabase Postgrest client, I haven't been able to mock the calls to return mock data.
Some references I've seen, but nothing really works:
- https://github.com/R3HP/food_order_app_clean_architecture/blob/6c491486eed92b2582f28c2b0badbbe6c9722235/test/features/order/data/dataSource/order_data_source_test.dart
- https://github.com/dwyl/supabase-flutter-demo/blob/main/test/widget_test.dart
An example code to be tested:
class EntitiesProvider with ChangeNotifier {
final supabase = GetIt.instance.get<SupabaseClient>();
var _entities = <Entity>[];
UnmodifiableListView<Entity> entities = UnmodifiableListView(_entities);
Future<void> fetchEntities() async {
// some logic
_entities = await supabase.from("entities").select().map((e) => Entity.fromJson(e)).toList();
// some logic
}
}
I know there are ways to work around this, but I'm looking for a blessed and official way from the Supabase team.