[Unit Testing] Difficulties with mocking Firebase services in Jest/Angular environment
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 28/100
- Loại issue
- Tài liệu
- Độ rõ ràng
- Cần làm rõ
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- angular, firebase, typescript
Hướng nghiên cứu
Bắt đầu bằng cách tái hiện FirebaseError: No Firebase App '[DEFAULT]' has been created trong một ứng dụng Angular sử dụng @angular/fire/compat hoặc @angular/fire với Jest. Xem xét sự tương tác giữa getAuth(), initializeApp() và TestBed.configureTestingModule. Công việc được xem là hoàn thành khi repository cung cấp một chiến lược kiểm thử Jest đáng tin cậy, có tài liệu, hoặc một tiện ích cho các service Angular phụ thuộc vào Firebase.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- TypeScript
- Star
- 7.8k
- Fork
- 2.2k
- Merge trung bình
- 3 ngày 6 giờ
- Pull request đã merge (30 ngày)
- 5
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của angular/angularfire
-
comp: build/pipeline type: bug version: current (v17+)
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
angular/angularfire#3766 ·
-
comp: schematics type: bug version: current (v17+)
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 76/100
angular/angularfire#3768 ·
-
comp: docs type: chore version: current (v17+)
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 58/100
angular/angularfire#3764 ·
-
comp: firestore comp: ssr priority: P0 (critical) type: feature version: current (v17+)
angular/angularfire#3757 · 1 người được giao ·
-
Six `firebase` entry points have no `@angular/fire` equivalent, so their exports are unreachable Đang mởcomp: core type: feature
angular/angularfire#3755 · 1 người được giao ·
Tất cả issue của angular/angularfire
Issue tương tự
-
[Bug]: Discord Activity titles with emoji are rejected as over 80 characters when they are not Đang mởclawsweeper:linked-pr-open clawsweeper:no-new-fix-pr clawsweeper:source-repro impact:message-loss issue-rating: 🦞 diamond lobster maturity:stable P2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Eynzof/Hermes-CN-Desktop#616 ·
-
ZCode 3.14.3 に対応する Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
supermomonga/zcode-acp#24 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
growthbook/growthbook#7100 ·
-
triage
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100