A simple usage example. Add firebase_auth_mocks and google_sign_in_mocks to dev dependencies.
import'package:firebase_auth_mocks/firebase_auth_mocks.dart';
import'package:google_sign_in_mocks/google_sign_in_mocks.dart';
main() {
// Mock sign in with Google.final googleSignIn = MockGoogleSignIn();
final signinAccount = await googleSignIn.signIn();
final googleAuth = await signinAccount.authentication;
finalAuthCredential credential = GoogleAuthProvider.getCredential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
// Sign in.final user = MockUser(
isAnonymous: false,
uid: 'someuid',
email: 'bob@somedomain.com',
displayName: 'Bob',
);
final auth = MockFirebaseAuth(mockUser: user);
final result = await auth.signInWithCredential(credential);
final user = await result.user;
print(user.displayName);
}
Features
MockFirebaseAuth supports:
instantiating in a signed-in state or not: MockFirebaseAuth(signedIn: true/false).
firing events on sign-in to authStateChanges and userChanges.
signInWithCredential, signInWithEmailAndPassword, signInWithCustomToken,
signInAnonymously, createUserWithEmailAndPassword, signInWithPopup and signInWithProvider signs in.
sendSignInLinkToEmail, confirmPasswordReset and verifyPasswordResetCode.
verifyPhoneNumber resolves codeSent.
signOut
sendPasswordResetEmail
currentUser
the ability to throw exceptions using whenCalling(...).on(...).thenThrow(...). See usage details below. Currently these methods are supported: signInWithCredential, signInWithPopup, signInWithProvider, signInWithEmailAndPassword, createUserWithEmailAndPassword, signInWithCustomToken, signInAnonymously, signOut, sendPasswordResetEmail, sendSignInLinkToEmail, confirmPasswordReset, verifyPasswordResetCode. If you need another method supported, feel free to file a ticket, or better propose a PR.
pass auth information (uid, custom claims...) to Fake Cloud Firestore for security rules via authForFakeFirestore. See the docs at fake_cloud_firestore for usage.