पैकेज, रिपॉज़िटरी और ऐप श्रेणियाँ खोजें

पैकेज विवरणv0.16.0

firebase_auth_mocks

Firebase Auth के लिए मॉक। Firebase Authentication के साथ यूनिट टेस्ट लिखने के लिए `google_sign_in_mocks` के साथ इस पैकेज का उपयोग करें।

AndroidiOSWebmacOSWindows
30-दिन डाउनलोड
1.5 लाख
लाइक
105
Pub अंक
140

पैकेज इंस्टॉल करें

flutter pub add firebase_auth_mocks

पैकेज अवलोकन

सार्वजनिक जानकारी से बना चयन मार्गदर्शन। केवल संदर्भ हेतु।

एक टेस्टिंग पैकेज जो Firebase Authentication के मॉक इम्प्लीमेंटेशन प्रदान करता है, जिससे डेवलपर्स वास्तविक Firebase बैकएंड से जुड़े बिना प्रमाणीकरण फ्लो का सिमुलेशन कर सकते हैं। यह `google_sign_in_mocks` के साथ काम करता है ताकि Flutter ऐप्स में प्रमाणीकरण से संबंधित लॉजिक के यूनिट टेस्ट को सुगम बनाया जा सके। नियंत्रित वातावरण में लॉगिन, साइनआउट और उपयोगकर्ता अवस्था परिवर्तन के टेस्ट के लिए आदर्श है। यह पैकेज Android, iOS, Web, macOS और Windows सहित सभी प्रमुख प्लेटफॉर्म का समर्थन करता है, जिससे वातावरणों के बीच समान टेस्ट व्यवहार सुनिश्चित होता है।

उपयोग

  • एकाधिक प्रमाणीकरण प्रवाह का एकाधिक परीक्षण
  • उपयोगकर्ता लॉगिन और लॉगआउट का अनुकरण करना
  • विभिन्न प्रमाणीकरण अवस्थाओं के तहत ऐप के व्यवहार का परीक्षण
  • उपयोगकर्ता प्रमाणीकरण के आधार पर UI अद्यतन की जांच करना
  • ऑफलाइन परीक्षण परिदृश्य विकसित करना

मुख्य विशेषताएँ

  • मॉक FirebaseAuth इंस्टेंस
  • google_sign_in_mocks के साथ एकीकरण
  • प्लेटफॉर्म-अनुकूल परीक्षण
  • सभी फ्लटर प्लेटफॉर्म को समर्थन करता है
  • परीक्षण वातावरण के लिए सरल सेटअप

इनके लिए उपयुक्त

  • फ्लटर विकासकर्मी परीक्षण लिखते हैं
  • TDD या BDD का अभ्यास करने वाली टीमें
  • Firebase Auth पर निर्भर ऐप्स
  • टेस्ट-ड्रिवन डेवलपमेंट वर्कफ्लो
  • विश्वसनीय परीक्षण की आवश्यकता वाले CI/CD पाइपलाइंस

विचार योग्य बातें

  • उत्पादन उपयोग के लिए नहीं
  • साथी google_sign_in_mocks की आवश्यकता है
  • मॉक व्यवहार वास्तविक दुनिया के किनारे के मामलों को दर्शाने में असफल हो सकता है
  • बेसिक प्रमाणीकरण अवस्था सिमुलेशन के लिए सीमित
  • रियल-टाइम प्राधिकरण सुनने वालों का समर्थन नहीं करता है

मूल README

संबंधित सोर्स रिपॉज़िटरी के मूल README का स्नैपशॉट। नवीनतम सामग्री के लिए रिपॉज़िटरी देखें।

Firebase Auth Mocks

pub package Unit Tests Buy Me A Coffee

Mocks for Firebase Auth. Use this package with google_sign_in_mocks to write unit tests involving Firebase Authentication.

Usage

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;
    final AuthCredential 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.
    • authStateChanges, userChanges, idTokenChanges stream listeners
  • UserCredential contains the provided User with the information of your choice.
  • User supports:
    • updateDisplayName
    • reauthenticateWithCredential
    • updatePassword
    • delete
    • sendEmailVerification
    • getIdToken and getIdTokenResult
    • the ability to throw exceptions on reauthenticateWithCredential, updatePassword, delete, sendEmailVerification, verifyPhoneNumber, linkWithCredential, linkWithProvider, unlink, User.reload, User.verifyBeforeUpdateEmail.

Throwing exceptions

Regardless of the parameters
whenCalling(Invocation.method(#signInWithCredential, null))
  .on(auth)
  .thenThrow(FirebaseAuthException(code: 'bla'));
expect(
  () => auth.signInWithCredential(FakeAuthCredential()),
  throwsA(isA<FirebaseAuthException>()),
);
Depending on positional parameters
Equality
final auth = MockFirebaseAuth();
whenCalling(Invocation.method(#verifyPhoneNumber, '12-345-6789'))
    .on(auth)
    .thenThrow(FirebaseAuthException(code: 'invalid-action-code'));
expect(() => auth.verifyPhoneNumber('12-345-6789'),
    throwsA(isA<FirebaseAuthException>()));
expect(() => auth.verifyPhoneNumber('00-222-4444'),
    returnsNormally);
Using any other matcher

Supports all of the matchers from the Dart matchers library.

final auth = MockFirebaseAuth();
whenCalling(Invocation.method(
        #confirmPasswordReset, null, {#code: contains('code')}))
    .on(auth)
    .thenThrow(FirebaseAuthException(code: 'invalid-action-code'));
expect(
  () => auth.confirmPasswordReset(
    code: 'code',
    newPassword: 'password',
  ),
  throwsA(isA<FirebaseAuthException>()),
);
expect(
  () => auth.confirmPasswordReset(
    code: '1234',
    newPassword: 'password',
  ),
  returnsNormally,
);
Depending on named parameters

You can match some or all named parameters. If you omit a named parameter, the library matches it against anything.

In this example, it will throw an exception if the code contains the String 'code', no matter the value of newPassword.

whenCalling(Invocation.method(
          #confirmPasswordReset, null, {#code: contains('code')}))
      .on(auth)
      .thenThrow(FirebaseAuthException(code: 'invalid-action-code'));
  expect(
    () async => await auth.confirmPasswordReset(
      code: 'code',
      newPassword: 'password',
    ),
    throwsA(isA<FirebaseAuthException>()),
  );
  expect(
      () => auth.confirmPasswordReset(
            code: '10293',
            newPassword: 'password',
          ),
      returnsNormally);

Compatibility table

firebase_auth firebase_auth_mocks
6.0.0 0.15.0
5.0.0 0.14.0
4.0.0 0.9.0
3.5.0 0.8.7

Features and bugs

Please file feature requests and bugs at the issue tracker.

श्रेणियाँ

निर्भरताएँ

निर्भरता सूची 8 आइटम

सोर्स रिपॉज़िटरी

इस पैकेज का उपयोग करने वाले प्रोजेक्ट