File tree Expand file tree Collapse file tree 5 files changed +22
-3
lines changed Expand file tree Collapse file tree 5 files changed +22
-3
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' @firebase/app ' : patch
3
+ ---
4
+
5
+ Make the error more helpful when ` getApp() ` is called before ` initializeApp() ` .
Original file line number Diff line number Diff line change @@ -199,9 +199,20 @@ describe('API tests', () => {
199
199
expect ( getApp ( appName ) ) . to . equal ( app ) ;
200
200
} ) ;
201
201
202
- it ( 'throws retrieving a non existing App' , ( ) => {
202
+ it ( 'throws retrieving a non existing App (custom name) ' , ( ) => {
203
203
expect ( ( ) => getApp ( 'RandomName' ) ) . throws ( / N o F i r e b a s e A p p ' R a n d o m N a m e ' / ) ;
204
204
} ) ;
205
+
206
+ it ( 'throws retrieving a non existing App (default name)' , ( ) => {
207
+ expect ( ( ) => getApp ( ) ) . throws ( / N o F i r e b a s e A p p / ) ;
208
+ } ) ;
209
+
210
+ it ( 'does not throw on a non existing App (default name) if a defaults object exists' , ( ) => {
211
+ global . __FIREBASE_DEFAULTS__ = { config : { apiKey : 'abcd' } } ;
212
+ const app = getApp ( ) ;
213
+ expect ( app . options . apiKey ) . to . equal ( 'abcd' ) ;
214
+ global . __FIREBASE_DEFAULTS__ = undefined ;
215
+ } ) ;
205
216
} ) ;
206
217
207
218
describe ( 'getApps' , ( ) => {
Original file line number Diff line number Diff line change @@ -202,7 +202,7 @@ export function initializeApp(
202
202
*/
203
203
export function getApp ( name : string = DEFAULT_ENTRY_NAME ) : FirebaseApp {
204
204
const app = _apps . get ( name ) ;
205
- if ( ! app && name === DEFAULT_ENTRY_NAME ) {
205
+ if ( ! app && name === DEFAULT_ENTRY_NAME && getDefaultAppConfig ( ) ) {
206
206
return initializeApp ( ) ;
207
207
}
208
208
if ( ! app ) {
Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ export const enum AppError {
34
34
const ERRORS : ErrorMap < AppError > = {
35
35
[ AppError . NO_APP ] :
36
36
"No Firebase App '{$appName}' has been created - " +
37
- 'call Firebase App. initializeApp()' ,
37
+ 'call initializeApp() first ' ,
38
38
[ AppError . BAD_APP_NAME ] : "Illegal App name: '{$appName}" ,
39
39
[ AppError . DUPLICATE_APP ] :
40
40
"Firebase App named '{$appName}' already exists with different options or config" ,
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ import {
30
30
_getProvider ,
31
31
_removeServiceInstance
32
32
} from './internal' ;
33
+ import { logger } from './logger' ;
33
34
34
35
declare module '@firebase/component' {
35
36
interface NameServiceMapping {
@@ -60,10 +61,12 @@ describe('Internal API tests', () => {
60
61
it ( 'does NOT throw registering duplicate components' , ( ) => {
61
62
const app = initializeApp ( { } ) as FirebaseAppImpl ;
62
63
const testComp = createTestComponent ( 'test' ) ;
64
+ const debugStub = stub ( logger , 'debug' ) ;
63
65
64
66
_addComponent ( app , testComp ) ;
65
67
66
68
expect ( ( ) => _addComponent ( app , testComp ) ) . to . not . throw ( ) ;
69
+ expect ( debugStub ) . to . be . called ;
67
70
expect ( app . container . getProvider ( 'test' ) . getComponent ( ) ) . to . equal (
68
71
testComp
69
72
) ;
You can’t perform that action at this time.
0 commit comments