Skip to content
pubscout

firebase_auth_mocks

0.16.0, released 4 weeks ago by wafrat.com

Mocks for Firebase Auth to enable unit testing of authentication flows.

WASM-ready
$ flutter pub add firebase_auth_mocks
Source repository

What it does

Provides a MockFirebaseAuth that mimics Firebase Auth behavior, including sign‑in, sign‑out, user management and event streams. It also allows throwing custom exceptions for testing error handling.

AI-written summary of version 0.16.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • Writing unit tests for Firebase Auth flows
  • Testing error handling in authentication
  • Mocking Firebase Auth in CI environments

Skip it when

  • Replacing real Firebase Auth in production code
  • Using in performance‑critical production builds

Strengths

  • Full API coverage of firebase_auth
  • Supports event streams (authStateChanges, userChanges, idTokenChanges)
  • Customizable exception throwing
  • Compatible with google_sign_in_mocks for Google sign‑in tests

Weaknesses

  • Only works with Flutter (no pure Dart support)
  • Requires firebase_auth dependency, adding weight to the project
  • No support for all firebase_auth methods (e.g., fetchSignInMethodsForEmail removed)
  • Documentation focuses on usage, not advanced configuration

Setup

Kind
Flutter widgets
Effort
Low
Code generation
No
Direct dependencies
8

Add to dev_dependencies, import package, no special permissions or build_runner needed

import 'package:firebase_auth_mocks/firebase_auth_mocks.dart';
import 'package:google_sign_in_mocks/google_sign_in_mocks.dart';

final auth = MockFirebaseAuth();
final googleSignIn = MockGoogleSignIn();
final account = await googleSignIn.signIn();
final credential = GoogleAuthProvider.getCredential(
  accessToken: (await account.authentication).accessToken,
  idToken: (await account.authentication).idToken,
);
final userCredential = await auth.signInWithCredential(credential);
print(userCredential.user?.displayName);

Works with

Packages commonly used together with firebase_auth_mocks: ones it builds on, ones built on it, and its own family.