testing library

Helpers for the widget and unit tests of an app built on supabase_flutter.

initializeTestSupabase initializes Supabase the way a test needs it: in-memory persistence, no token auto refresh, no deep link detection, and an unsigned test key. Answer the HTTP traffic with a MockSupabaseHttpClient from package:supabase_test, and realtime with its MockRealtimeTransport:

import 'package:supabase_flutter/testing.dart';
import 'package:supabase_test/supabase_test.dart';

testWidgets('shows the open todos', (tester) async {
  final httpClient = MockSupabaseHttpClient()
    ..stubTable('todos', rows: [{'id': 1, 'task': 'Ship it'}]);
  final supabase = await initializeTestSupabase(httpClient: httpClient);
  addTearDown(supabase.dispose);

  await tester.pumpWidget(const MyApp());
  await tester.pumpAndSettle();

  expect(find.text('Ship it'), findsOneWidget);
});

Properties

testPublishableKey String
The publishable key initializeTestSupabase uses by default: an unsigned JWT carrying the anon role, which the mocked services never verify.
final

Functions

initializeTestSupabase({Client? httpClient, String url = 'http://localhost:54321', String? publishableKey, Map<String, String>? headers, WebSocketTransport? realtimeTransport, AuthAsyncStorage? asyncStorage, bool autoRefreshToken = false}) Future<Supabase>
Initializes Supabase for a test and returns the instance.