Skip to content

Testing and mocking guide #864

Open
Open
@tomasAlabes

Description

@tomasAlabes

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:

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions