Skip to content

Commit 14657e7

Browse files
committed
Added tests
1 parent 0c2d504 commit 14657e7

File tree

1 file changed

+24
-26
lines changed

1 file changed

+24
-26
lines changed

test/unit/app/firebase-namespace.spec.ts

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import { getSdkVersion } from '../../../src/utils/index';
4949

5050
import {
5151
app, auth, messaging, machineLearning, storage, firestore, database,
52-
instanceId, installations, projectManagement, securityRules , remoteConfig, appCheck,
52+
instanceId, installations, projectManagement, securityRules, remoteConfig, appCheck,
5353
} from '../../../src/firebase-namespace-api';
5454
import { AppCheck as AppCheckImpl } from '../../../src/app-check/app-check';
5555
import { Auth as AuthImpl } from '../../../src/auth/auth';
@@ -207,33 +207,29 @@ describe('FirebaseNamespace', () => {
207207
}).to.throw('Invalid Firebase app name "" provided. App name must be a non-empty string.');
208208
});
209209

210-
it('should throw given a name corresponding to an existing app', () => {
210+
it('should not throw given a name corresponding to an existing app', () => {
211+
let app1: App | undefined;
212+
let app2: App | undefined;
211213
expect(() => {
212-
firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName);
213-
firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName);
214-
}).to.throw(`Firebase app named "${mocks.appName}" already exists.`);
214+
app1 = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName);
215+
app2 = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName);
216+
}).to.not.throw();
217+
expect(app1).to.equal(app2);
215218
});
216219

217-
it('should throw given no app name if the default app already exists', () => {
220+
it('should not throw given no app name if the default app already exists', () => {
221+
let app1: App | undefined;
222+
let app2: App | undefined;
218223
expect(() => {
219-
firebaseNamespace.initializeApp(mocks.appOptions);
220-
firebaseNamespace.initializeApp(mocks.appOptions);
221-
}).to.throw('The default Firebase app already exists.');
224+
app1 = firebaseNamespace.initializeApp(mocks.appOptions);
225+
app2 = firebaseNamespace.initializeApp(mocks.appOptions);
226+
}).to.not.throw();
227+
expect(app1).to.equal(app2);
222228

223229
expect(() => {
224-
firebaseNamespace.initializeApp(mocks.appOptions);
225-
firebaseNamespace.initializeApp(mocks.appOptions, DEFAULT_APP_NAME);
226-
}).to.throw('The default Firebase app already exists.');
227-
228-
expect(() => {
229-
firebaseNamespace.initializeApp(mocks.appOptions, DEFAULT_APP_NAME);
230-
firebaseNamespace.initializeApp(mocks.appOptions);
231-
}).to.throw('The default Firebase app already exists.');
232-
233-
expect(() => {
234-
firebaseNamespace.initializeApp(mocks.appOptions, DEFAULT_APP_NAME);
235-
firebaseNamespace.initializeApp(mocks.appOptions, DEFAULT_APP_NAME);
236-
}).to.throw('The default Firebase app already exists.');
230+
app2 = firebaseNamespace.initializeApp(mocks.appOptions, DEFAULT_APP_NAME);
231+
}).to.not.throw();
232+
expect(app1).to.equal(app2);
237233
});
238234

239235
it('should return a new app with the provided options and app name', () => {
@@ -248,10 +244,12 @@ describe('FirebaseNamespace', () => {
248244
});
249245

250246
it('should allow re-use of a deleted app name', () => {
251-
let app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName);
252-
return app.delete().then(() => {
253-
app = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName);
254-
expect(firebaseNamespace.app(mocks.appName)).to.deep.equal(app);
247+
const app1 = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName);
248+
let app2: App | undefined;
249+
return app1.delete().then(() => {
250+
app2 = firebaseNamespace.initializeApp(mocks.appOptions, mocks.appName);
251+
expect(firebaseNamespace.app(mocks.appName)).to.deep.equal(app2);
252+
expect(app2).to.not.equal(app1);
255253
});
256254
});
257255

0 commit comments

Comments
 (0)