[Unit Testing] Difficulties with mocking Firebase services in Jest/Angular environment
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Accessibilité débutants
- 28/100
- Type d'issue
- Documentation
- Clarté
- À clarifier
- Activité
- À l'abandon
- Stack technique
- angular, firebase, typescript
Piste de recherche
Commencez par reproduire le FirebaseError: No Firebase App '[DEFAULT]' has been created dans une application Angular utilisant @angular/fire/compat ou @angular/fire avec Jest. Examinez les interactions entre getAuth(), initializeApp() et TestBed.configureTestingModule. Le travail sera considéré comme terminé lorsque le dépôt fournira une stratégie de test Jest fiable et documentée, ou un utilitaire pour les services Angular dépendant de Firebase.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
When using @angular/fire/compat or @angular/fire to build Angular applications, we encounter significant challenges when trying to perform unit tests with a testing framework like Jest.
The main issue stems from the tight coupling of the Auth service (and others like Storage or Firestore) to the FirebaseApp instance. Functions like getAuth() and initializeApp() are called implicitly or explicitly by the AngularFire component, which leads to the FirebaseError: No Firebase App '[DEFAULT]' has been created error.
The core problem is that we cannot properly mock these functions before the component attempts to access them. Standard mocking techniques (e.g., jest.mock, TestBed.configureTestingModule providers) fail because the functions are either read-only properties or are called in a context where a FirebaseApp instance is expected, but not yet available.
This forces developers to use fragile workarounds to get tests to pass, making the testing process difficult and prone to errors. It also discourages writing comprehensive unit tests for components that depend on Firebase services.
Suggested Improvement:
We would appreciate it if the AngularFire team could provide an official, documented strategy for unit testing with Jest. A potential solution could involve a testing utility library or a recommended pattern that correctly mocks the underlying FirebaseApp instance and its dependent services in a reliable way.
- Langage dominant
- TypeScript
- Étoiles
- 7.8k
- Forks
- 2.2k
- Merge moyen
- 3 j 6 h
- PR mergées (30 j)
- 5
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de angular/angularfire
-
comp: build/pipeline type: bug version: current (v17+)
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
angular/angularfire#3766 ·
-
comp: schematics type: bug version: current (v17+)
Difficulté 3/5 1-2 jours Accessibilité débutants 76/100
angular/angularfire#3768 ·
-
comp: docs type: chore version: current (v17+)
Difficulté 4/5 3-5 jours Accessibilité débutants 58/100
angular/angularfire#3764 ·
-
comp: firestore comp: ssr priority: P0 (critical) type: feature version: current (v17+)
angular/angularfire#3757 · 1 personne assignée ·
-
Six `firebase` entry points have no `@angular/fire` equivalent, so their exports are unreachable Ouvertecomp: core type: feature
angular/angularfire#3755 · 1 personne assignée ·
Toutes les issues de angular/angularfire
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
-
bug v2
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
modelcontextprotocol/inspector#2458 · 1 commentaire ·
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 75/100
railmapgen/rmp-gallery#4068 ·
-
Mend: dependency security vulnerability status: needs triage 🕵️♀️
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
carbon-design-system/ibm-products#9907 ·