soumak77 / firebase-mock

Firebase mock library for writing unit tests
https://soumak77.github.io/firebase-mock
349 stars 97 forks source link

`initializeApp` does not return `functions` method #155

Open crutchcorn opened 4 years ago

crutchcorn commented 4 years ago

The code usage I'm having looks like:

export const firebaseApp = firebase.initializeApp(firebaseConfig);
// Used for creating child accounts, primarily
export const firebaseSecondaryApp = firebase.initializeApp(firebaseConfig, 'Secondary');
export const firebaseAuth = firebaseApp.auth();
export const firebaseSecondaryAuth = firebaseSecondaryApp.auth();
export const firebaseDb = firebaseApp.database();
export const firebaseFunc = firebaseApp.functions();

With my mocks just looking like this:

jest.mock('firebase/auth', () => ({}));
jest.mock('firebase/functions', () => ({}));
jest.mock('firebase/database', () => ({}));
jest.mock('firebase/app', () => {
    const firebaseMock = require('firebase-mock');

    const mockDatabase = new firebaseMock.MockFirebase();
    const mockAuth = new firebaseMock.MockFirebase();
    const mockSDK = new firebaseMock.MockFirebaseSdk((path: any) => {
        return path ? mockDatabase.child(path) : mockDatabase;
    }, () => {
        return mockAuth;
    });

    const firebaseApp = mockSDK.initializeApp();

    return mockSDK;
});

However my code gives me errors as there is no functions method on the return value for initializeApp