[Unit Testing] Difficulties with mocking Firebase services in Jest/Angular environment
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Anfängerfreundlichkeit
- 28/100
- Issue-Typ
- Dokumentation
- Klarheit
- Muss geklärt werden
- Aktivitätsstatus
- Veraltet
- Tech-Stack
- angular, firebase, typescript
Rechercherichtung
Beginnen Sie damit, den FirebaseError: No Firebase App '[DEFAULT]' has been created in einer Angular-Anwendung mit @angular/fire/compat oder @angular/fire unter Verwendung von Jest zu reproduzieren. Untersuchen Sie die Wechselwirkungen zwischen getAuth(), initializeApp() und TestBed.configureTestingModule. Als erledigt gilt die Aufgabe, wenn das Repository eine zuverlässige, dokumentierte Jest-Teststrategie oder ein Dienstprogramm für Firebase-abhängige Angular-Services bereitstellt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 7.8k
- Forks
- 2.2k
- Ø Merge
- 3 T. 6 Std.
- Gemergte PRs (30 T.)
- 5
Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus angular/angularfire
-
comp: build/pipeline type: bug version: current (v17+)
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
angular/angularfire#3766 ·
-
comp: schematics type: bug version: current (v17+)
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 76/100
angular/angularfire#3768 ·
-
comp: docs type: chore version: current (v17+)
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 58/100
angular/angularfire#3764 ·
-
comp: firestore comp: ssr priority: P0 (critical) type: feature version: current (v17+)
angular/angularfire#3757 · 1 zugewiesene Person ·
-
Six `firebase` entry points have no `@angular/fire` equivalent, so their exports are unreachable Offencomp: core type: feature
angular/angularfire#3755 · 1 zugewiesene Person ·
Alle Issues in angular/angularfire
Ähnliche Issues
-
blocklist removal
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
MetaMask/eth-phishing-detect#296544 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
pastelsky/bundlephobia#1122 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
-
category/development priority/P2 scope/file-operations scope/testing type/enhancement
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
-
Enatega Customer and Rider app: Add-ons price is not visible to customer after order is placed. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100