Skip to content

Commit f3b955c

Browse files
committed
fix(app, types): initializeApp returns Promise<FirebaseApp>
previously was <FirebaseApp> so it seemed sync vs async All of the E2E tests in the area have been enabled and tested (by purposefully modifying expected output to not match) to fail as expected, and pass with correct expected output
1 parent 0506703 commit f3b955c

File tree

2 files changed

+39
-29
lines changed

2 files changed

+39
-29
lines changed

packages/app/e2e/app.e2e.js

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,10 @@ describe('firebase', function () {
3737
should.equal(firebase.app().options.storageBucket, platformAppConfig.storageBucket);
3838
});
3939

40-
xit('it should initialize dynamic apps', function () {
41-
const name = `testscoreapp${FirebaseHelpers.id}`;
42-
const platformAppConfig = FirebaseHelpers.app.config();
43-
return firebase.initializeApp(platformAppConfig, name).then(newApp => {
44-
newApp.name.should.equal(name);
45-
newApp.toString().should.equal(name);
46-
newApp.options.apiKey.should.equal(platformAppConfig.apiKey);
47-
return newApp.delete();
48-
});
49-
});
50-
5140
it('SDK_VERSION should return a string version', function () {
5241
firebase.SDK_VERSION.should.be.a.String();
5342
});
54-
});
5543

56-
// eslint-disable-next-line mocha/max-top-level-suites
57-
describe('firebase -> X', function () {
5844
it('apps should provide an array of apps', function () {
5945
should.equal(!!firebase.apps.length, true);
6046
should.equal(firebase.apps.includes(firebase.app('[DEFAULT]')), true);
@@ -66,31 +52,55 @@ describe('firebase -> X', function () {
6652
should.equal(firebase.app().automaticDataCollectionEnabled, false);
6753
});
6854

69-
xit('apps can be deleted', async function () {
55+
it('it should initialize dynamic apps', async function () {
7056
const name = `testscoreapp${FirebaseHelpers.id}`;
7157
const platformAppConfig = FirebaseHelpers.app.config();
7258
const newApp = await firebase.initializeApp(platformAppConfig, name);
73-
7459
newApp.name.should.equal(name);
7560
newApp.toString().should.equal(name);
7661
newApp.options.apiKey.should.equal(platformAppConfig.apiKey);
62+
return newApp.delete();
63+
});
7764

78-
await newApp.delete();
65+
it('should error if dynamic app initialization values are incorrect', async function () {
66+
try {
67+
await firebase.initializeApp({ appId: 'myid' }, 'myname');
68+
throw new Error('Should have rejected incorrect initializeApp input');
69+
} catch (e) {
70+
e.message.should.equal("Missing or invalid FirebaseOptions property 'apiKey'.");
71+
}
72+
});
7973

80-
(() => {
81-
newApp.delete();
82-
}).should.throw(`Firebase App named '${name}' already deleted`);
74+
it('apps can be deleted, but only once', async function () {
75+
const name = `testscoreapp${FirebaseHelpers.id}`;
76+
const platformAppConfig = FirebaseHelpers.app.config();
77+
const newApp = await firebase.initializeApp(platformAppConfig, name);
8378

84-
(() => {
79+
newApp.name.should.equal(name);
80+
newApp.toString().should.equal(name);
81+
newApp.options.apiKey.should.equal(platformAppConfig.apiKey);
82+
83+
await newApp.delete();
84+
try {
85+
await newApp.delete();
86+
} catch (e) {
87+
e.message.should.equal(`Firebase App named '${name}' already deleted`);
88+
}
89+
try {
8590
firebase.app(name);
86-
}).should.throw(`No Firebase App '${name}' has been created - call firebase.initializeApp()`);
91+
} catch (e) {
92+
e.message.should.equal(
93+
`No Firebase App '${name}' has been created - call firebase.initializeApp()`,
94+
);
95+
}
8796
});
8897

89-
xit('prevents the default app from being deleted', async function () {
90-
firebase
91-
.app()
92-
.delete()
93-
.should.be.rejectedWith('Unable to delete the default native firebase app instance.');
98+
it('prevents the default app from being deleted', async function () {
99+
try {
100+
await firebase.app().delete();
101+
} catch (e) {
102+
e.message.should.equal('Unable to delete the default native firebase app instance.');
103+
}
94104
});
95105

96106
it('extendApp should provide additional functionality', function () {

packages/app/lib/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ export namespace ReactNativeFirebase {
159159
* @param options Options to configure the services used in the App.
160160
* @param config The optional config for your firebase app
161161
*/
162-
initializeApp(options: FirebaseAppOptions, config?: FirebaseAppConfig): FirebaseApp;
162+
initializeApp(options: FirebaseAppOptions, config?: FirebaseAppConfig): Promise<FirebaseApp>;
163163

164164
/**
165165
* Create (and initialize) a FirebaseApp.
@@ -168,7 +168,7 @@ export namespace ReactNativeFirebase {
168168
* @param name The optional name of the app to initialize ('[DEFAULT]' if
169169
* omitted)
170170
*/
171-
initializeApp(options: FirebaseAppOptions, name?: string): FirebaseApp;
171+
initializeApp(options: FirebaseAppOptions, name?: string): Promise<FirebaseApp>;
172172

173173
/**
174174
* Retrieve an instance of a FirebaseApp.

0 commit comments

Comments
 (0)