Description
Version info
React:
react@16.13.1
Firebase:
@firebase/testing@0.20.4
ReactFire:
reactfire@2.0.3
Other (e.g. Node, browser, operating system) (if applicable):
Using react-scripts@3.4.1
Test case
https://jsfiddle.net/j1pmo8Lu/6/
Steps to reproduce
I have created a TestProvider that I use to render all of my jest tests with the appropriate contexts like firebase, routing, etc.
import { FirebaseAppProvider, useUser } from 'reactfire';
import firebase from '@firebase/app';
import * as firebaseTesting from '@firebase/testing';
import firebaseConfig from './constants/firebaseConfig'
let app;
if (!firebase.apps.length) {
app = firebaseTesting.initializeTestApp({
projectId: process.env.REACT_APP_FB_projectId,
databaseName: process.env.REACT_APP_FB_projectId,
auth: { uid: process.env.TEST_UID },
});
}
function TestProviders({ children }) {
return (
<FirebaseAppProvider firebase={app} config={firebaseConfig}>
<React.Suspense fallback="loading">
{children}
</React.Suspense>
</FirebaseAppProvider>
);
}
describe('useUser', () => {
afterEach(() => {
jest.clearAllMocks();
});
it('should return users auth information', () => {
const { result } = renderHook(() => useUser(),
{ wrapper: TestProviders }
);
expect(result.current[0]).toStrictEqual(mock.userObject);
});
});
I like to use the emulators to keep things fast and independent, so I wanted to get it set up in the emulators. I initializeTestApp
and pass it in the firebaseApp prop in FirebaseAppProvider (copied this from your tests) and try to run some tests. I get an error "Invalid Api Key"
Then I added the firebase config to the config
prop in FirebaseAppProvider
and it worked.
I'd think that since I passed in an initialized firebase instance, what would it need the config for?
Is this expected?
Expected behavior
I'd expect it to not need the firebaseConfig
if you pass in an initialized firebase app.
Actual behavior
Throws INVALID_API_KEY error.