Skip to content

Commit

Permalink
update to isFirebaseServerApp to take null | undef
Browse files Browse the repository at this point in the history
  • Loading branch information
DellaBitta committed Dec 19, 2024
1 parent 9da69bc commit 9a1299b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
27 changes: 25 additions & 2 deletions packages/app/src/internal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { expect } from 'chai';
import { stub } from 'sinon';
import '../test/setup';
import { createTestComponent, TestService } from '../test/util';
import { initializeApp, getApps, deleteApp } from './api';
import { initializeApp, initializeServerApp, getApps, deleteApp } from './api';
import { FirebaseAppImpl } from './firebaseApp';
import {
_addComponent,
Expand All @@ -28,9 +28,11 @@ import {
_components,
_clearComponents,
_getProvider,
_removeServiceInstance
_removeServiceInstance,
_isFirebaseServerApp
} from './internal';
import { logger } from './logger';
import { isBrowser } from '@firebase/util';

declare module '@firebase/component' {
interface NameServiceMapping {
Expand Down Expand Up @@ -161,4 +163,25 @@ describe('Internal API tests', () => {
expect(instance1).to.not.equal(instance2);
});
});

describe('_isFirebaseServerApp', () => {
it('detects a valid FirebaseServerApp', () => {
if (!isBrowser()) {
// FirebaseServerApp isn't supported for execution in browser environments.
const app = initializeServerApp({}, {});
expect(_isFirebaseServerApp(app)).to.be.true;
}
});
it('a standard FirebaseApp returns false', () => {
const app = initializeApp({});
expect(_isFirebaseServerApp(app)).to.be.false;
});
it('a null object returns false', () => {
expect(_isFirebaseServerApp(null)).to.be.false;
});
it('undefined returns false', () => {
let app: undefined;
expect(_isFirebaseServerApp(app)).to.be.false;
});
});
});
5 changes: 4 additions & 1 deletion packages/app/src/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,11 @@ export function _isFirebaseApp(
* @internal
*/
export function _isFirebaseServerApp(
obj: FirebaseApp | FirebaseServerApp
obj: FirebaseApp | FirebaseServerApp | null | undefined
): obj is FirebaseServerApp {
if (obj === null || obj === undefined) {
return false;
}
return (obj as FirebaseServerApp).settings !== undefined;
}

Expand Down

0 comments on commit 9a1299b

Please sign in to comment.