1
- import firebase from 'firebase/app' ;
2
1
import { Observable , Subject } from 'rxjs' ;
3
2
import { TestBed } from '@angular/core/testing' ;
4
- import { AngularFireModule , FIREBASE_APP_NAME , FIREBASE_OPTIONS , FirebaseApp } from '@angular/fire' ;
5
- import { AngularFireAuth , AngularFireAuthModule } from '@angular/fire/auth' ;
3
+ import { AngularFireModule , FirebaseApp , FIREBASE_APPS } from '@angular/fire' ;
4
+ import { AngularFireAuth , AngularFireAuthModule , AUTH_INSTANCES } from '@angular/fire/auth' ;
6
5
import { COMMON_CONFIG } from '../test-config' ;
7
6
import { User } from 'firebase/auth' ;
8
7
import { rando } from '../firestore/utils.spec' ;
8
+ import { deleteApp } from 'firebase/app' ;
9
9
10
10
const firebaseUser = {
11
11
uid : '12345' ,
@@ -14,6 +14,7 @@ const firebaseUser = {
14
14
15
15
describe ( 'AngularFireAuth' , ( ) => {
16
16
let app : FirebaseApp ;
17
+ let apps : FirebaseApp [ ] ;
17
18
let afAuth : AngularFireAuth ;
18
19
let mockAuthState : Subject < User > ;
19
20
@@ -26,6 +27,7 @@ describe('AngularFireAuth', () => {
26
27
} ) ;
27
28
28
29
app = TestBed . inject ( FirebaseApp ) ;
30
+ apps = TestBed . inject ( FIREBASE_APPS ) ;
29
31
afAuth = TestBed . inject ( AngularFireAuth ) ;
30
32
31
33
mockAuthState = new Subject < User > ( ) ;
@@ -38,7 +40,7 @@ describe('AngularFireAuth', () => {
38
40
} ) ;
39
41
40
42
afterEach ( ( ) => {
41
- app . delete ( ) ;
43
+ apps . forEach ( app => deleteApp ( app ) ) ;
42
44
} ) ;
43
45
44
46
describe ( 'Zones' , ( ) => {
@@ -120,44 +122,46 @@ describe('AngularFireAuth', () => {
120
122
121
123
describe ( 'AngularFireAuth with different app' , ( ) => {
122
124
let app : FirebaseApp ;
123
- let afAuth : AngularFireAuth ;
125
+ let apps : FirebaseApp [ ] ;
126
+ let authInstances : AngularFireAuth [ ] ;
124
127
let firebaseAppName : string ;
125
128
126
129
beforeEach ( ( ) => {
127
130
firebaseAppName = rando ( ) ;
128
131
129
132
TestBed . configureTestingModule ( {
130
133
imports : [
131
- AngularFireModule . initializeApp ( COMMON_CONFIG , rando ( ) ) ,
132
- AngularFireAuthModule
133
- ] ,
134
- providers : [
135
- { provide : FIREBASE_APP_NAME , useValue : firebaseAppName } ,
136
- { provide : FIREBASE_OPTIONS , useValue : COMMON_CONFIG }
134
+ AngularFireModule . initializeApp ( COMMON_CONFIG , firebaseAppName ) ,
135
+ AngularFireAuthModule . initializeAuth ( { appName : firebaseAppName } )
137
136
]
138
137
} ) ;
139
138
140
139
app = TestBed . inject ( FirebaseApp ) ;
141
- afAuth = TestBed . inject ( AngularFireAuth ) ;
140
+ apps = TestBed . inject ( FIREBASE_APPS ) ;
141
+ authInstances = TestBed . inject ( AUTH_INSTANCES ) ;
142
142
} ) ;
143
143
144
144
afterEach ( ( ) => {
145
- app . delete ( ) ;
145
+ apps . forEach ( app => deleteApp ( app ) ) ;
146
146
} ) ;
147
147
148
148
describe ( '<constructor>' , ( ) => {
149
149
150
150
it ( 'should be an AngularFireAuth type' , ( ) => {
151
- expect ( afAuth instanceof AngularFireAuth ) . toEqual ( true ) ;
151
+ expect ( authInstances . length ) . toBeGreaterThan ( 0 ) ;
152
+ authInstances . forEach ( afAuth => {
153
+ expect ( afAuth instanceof AngularFireAuth ) . toEqual ( true ) ;
154
+ } ) ;
152
155
} ) ;
153
156
154
157
it ( 'should have an initialized Firebase app' , ( ) => {
155
- expect ( afAuth . name ) . toBeDefined ( ) ;
158
+ authInstances . forEach ( afAuth => {
159
+ expect ( afAuth . name ) . toBeDefined ( ) ;
160
+ } ) ;
156
161
} ) ;
157
162
158
- it ( 'should have an initialized Firebase app instance member' , async ( ) => {
159
- const appName = await afAuth . name ;
160
- expect ( appName ) . toEqual ( firebaseAppName ) ;
163
+ it ( 'should have an initialized Firebase app instance member' , ( ) => {
164
+ expect ( authInstances . map ( afAuth => afAuth . name ) . indexOf ( firebaseAppName ) ) . toBeGreaterThan ( - 1 ) ;
161
165
} ) ;
162
166
} ) ;
163
167
0 commit comments