Skip to content

Commit

Permalink
fix(app, types): initializeApp returns Promise<FirebaseApp>
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mikehardy committed Mar 5, 2021
1 parent 0506703 commit f3b955c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 29 deletions.
64 changes: 37 additions & 27 deletions packages/app/e2e/app.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,10 @@ describe('firebase', function () {
should.equal(firebase.app().options.storageBucket, platformAppConfig.storageBucket);
});

xit('it should initialize dynamic apps', function () {
const name = `testscoreapp${FirebaseHelpers.id}`;
const platformAppConfig = FirebaseHelpers.app.config();
return firebase.initializeApp(platformAppConfig, name).then(newApp => {
newApp.name.should.equal(name);
newApp.toString().should.equal(name);
newApp.options.apiKey.should.equal(platformAppConfig.apiKey);
return newApp.delete();
});
});

it('SDK_VERSION should return a string version', function () {
firebase.SDK_VERSION.should.be.a.String();
});
});

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

xit('apps can be deleted', async function () {
it('it should initialize dynamic apps', async function () {
const name = `testscoreapp${FirebaseHelpers.id}`;
const platformAppConfig = FirebaseHelpers.app.config();
const newApp = await firebase.initializeApp(platformAppConfig, name);

newApp.name.should.equal(name);
newApp.toString().should.equal(name);
newApp.options.apiKey.should.equal(platformAppConfig.apiKey);
return newApp.delete();
});

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

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

(() => {
newApp.name.should.equal(name);
newApp.toString().should.equal(name);
newApp.options.apiKey.should.equal(platformAppConfig.apiKey);

await newApp.delete();
try {
await newApp.delete();
} catch (e) {
e.message.should.equal(`Firebase App named '${name}' already deleted`);
}
try {
firebase.app(name);
}).should.throw(`No Firebase App '${name}' has been created - call firebase.initializeApp()`);
} catch (e) {
e.message.should.equal(
`No Firebase App '${name}' has been created - call firebase.initializeApp()`,
);
}
});

xit('prevents the default app from being deleted', async function () {
firebase
.app()
.delete()
.should.be.rejectedWith('Unable to delete the default native firebase app instance.');
it('prevents the default app from being deleted', async function () {
try {
await firebase.app().delete();
} catch (e) {
e.message.should.equal('Unable to delete the default native firebase app instance.');
}
});

it('extendApp should provide additional functionality', function () {
Expand Down
4 changes: 2 additions & 2 deletions packages/app/lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export namespace ReactNativeFirebase {
* @param options Options to configure the services used in the App.
* @param config The optional config for your firebase app
*/
initializeApp(options: FirebaseAppOptions, config?: FirebaseAppConfig): FirebaseApp;
initializeApp(options: FirebaseAppOptions, config?: FirebaseAppConfig): Promise<FirebaseApp>;

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

/**
* Retrieve an instance of a FirebaseApp.
Expand Down

1 comment on commit f3b955c

@vercel
Copy link

@vercel vercel bot commented on f3b955c Mar 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.