Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions packages/app/__tests__/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import firebase, {
setLogLevel,
} from '../lib';
import { Logger } from '../lib/internal/logger';
import { NativeFirebaseError } from '../lib/internal';

describe('App', function () {
describe('modular', function () {
Expand Down Expand Up @@ -121,4 +122,20 @@ describe('App', function () {
);
});
});

describe('`NativeFirebaseError` can cope with missing properties', function () {
it('missing `userInfo.code` does not error', function () {
const testNativeError = {
userInfo: undefined,
};
const testNativeFirebaseError = new NativeFirebaseError(
// @ts-ignore - using malformed object to test handling of malformed objects
testNativeError,
new Error().stack!,
'testNamespace',
);
expect(testNativeFirebaseError.namespace).toBe('testNamespace');
expect(testNativeFirebaseError.code).toBe('testNamespace/unknown');
});
});
});
14 changes: 7 additions & 7 deletions packages/app/lib/internal/NativeFirebaseError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default class NativeFirebaseError extends Error {
): NativeFirebaseError {
return new NativeFirebaseError(
{ userInfo: errorEvent },
stack || new Error().stack!,
stack ?? new Error().stack!,
namespace,
);
}
Expand All @@ -50,12 +50,12 @@ export default class NativeFirebaseError extends Error {

Object.defineProperty(this, 'code', {
enumerable: false,
value: `${this.namespace}/${userInfo.code || 'unknown'}`,
value: `${this.namespace}/${userInfo?.code ?? 'unknown'}`,
});

Object.defineProperty(this, 'message', {
enumerable: false,
value: `[${this.code}] ${userInfo.message || nativeError.message}`,
value: `[${this.code}] ${userInfo?.message ?? nativeError.message}`,
});

Object.defineProperty(this, 'jsStack', {
Expand All @@ -71,23 +71,23 @@ export default class NativeFirebaseError extends Error {
// Needed for MFA processing of errors on web
Object.defineProperty(this, 'customData', {
enumerable: false,
value: nativeError.customData || null,
value: nativeError.customData ?? null,
});

// Needed for MFA processing of errors on web
Object.defineProperty(this, 'operationType', {
enumerable: false,
value: nativeError.operationType || null,
value: nativeError.operationType ?? null,
});

Object.defineProperty(this, 'nativeErrorCode', {
enumerable: false,
value: userInfo.nativeErrorCode || null,
value: userInfo?.nativeErrorCode ?? null,
});

Object.defineProperty(this, 'nativeErrorMessage', {
enumerable: false,
value: userInfo.nativeErrorMessage || null,
value: userInfo?.nativeErrorMessage ?? null,
});

this.stack = NativeFirebaseError.getStackWithMessage(
Expand Down
2 changes: 1 addition & 1 deletion packages/app/lib/types/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export interface NativeErrorUserInfo {
}

export interface NativeError {
userInfo: NativeErrorUserInfo;
userInfo?: NativeErrorUserInfo;
message?: string;
customData?: any;
operationType?: string;
Expand Down
6 changes: 3 additions & 3 deletions packages/functions/__tests__/functions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ describe('Cloud Functions', function () {
});

it('`FunctionsModule` type is properly exposed to end user', function () {
const functionsInstance: Functions = (firebase.app() as unknown as FirebaseApp).functions();
const functionsInstance: Functions = getFunctions();
expect(functionsInstance).toBeDefined();
expect(functionsInstance.httpsCallable).toBeDefined();
expect(functionsInstance.httpsCallableFromUrl).toBeDefined();
Expand All @@ -126,12 +126,12 @@ describe('Cloud Functions', function () {
});

it('`Functions` type is properly exposed to end user', function () {
const functionsInstance: Functions = (firebase.app() as unknown as FirebaseApp).functions();
const functionsInstance: Functions = getFunctions();
expect(functionsInstance).toBeDefined();
});

it('`FirebaseApp` type is properly exposed to end user', function () {
const app = firebase.app() as unknown as FirebaseApp;
const app = getApp();
expect(app).toBeDefined();
expect(app.functions).toBeDefined();
});
Expand Down
Loading