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
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.
- uuidfirebase_auth_mocks depends on itGenerates and parses RFC‑4122/9562 UUIDs (v1‑v8) for Dart.
- equatablefirebase_auth_mocks depends on itProvides value‑based equality for Dart objects without manual == and hashCode.
- firebase_corefirebase_auth_mocks depends on itFlutter plugin that initializes Firebase and allows multiple Firebase app connections.
- firebase_authfirebase_auth_mocks depends on itFlutter plugin for Firebase Authentication enabling passwords, phone numbers, and identity providers.
- dart_jsonwebtokenfirebase_auth_mocks depends on itA Dart library for creating, signing, decoding and verifying JSON Web Tokens (JWT).
- mock_exceptionsfirebase_auth_mocks depends on itAllows throwing exceptions on specified method calls in fakes
- fake_cloud_firestoreSame familyFake implementation of Cloud Firestore for unit testing.
- firebase_storage_mocksSame familyMocks for Firebase Storage to write unit tests.