firebase_auth_mocks
firebase_auth_mocks copied to clipboard
Mocks for Firebase Auth. Use this package with google_sign_in_mocks to write unit tests involving Firebase Authentication.
Usage
A simple usage example:
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;
final AuthCredential credential = GoogleAuthProvider.getCredential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
// Sign in.
final user = MockUser(
isAnonymous: false,
uid: 'someuid',
email: '[email protected]',
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
anduserChanges
. -
signInWithCredential
,signInWithEmailAndPassword
,signInWithCustomToken
,signInAnonymously
andcreateUserWithEmailAndPassword
signs in. -
signOut
method. -
sendPasswordResetEmail
-
currentUser
- the ability to throw exceptions using
authExceptions
:
final auth = MockFirebaseAuth( authExceptions: AuthExceptions( signInWithCredential: FirebaseAuthException(code: 'invalid-credential'), ), );
- instantiating in a signed-in state or not:
-
UserCredential
contains the providedUser
with the information of your choice. -
User
supports:-
updateDisplayName
-
reauthenticateWithCredential
-
updatePassword
-
delete
-
sendEmailVerification
- the ability to throw exceptions.
-
Features and bugs
Please file feature requests and bugs at the issue tracker.