- Using react with firestore as my database running as a local emulator.
- Testing with react-script test which uses jest.
Now when calling firestore set() and get() functions from my react app in the browser everything works. But when unit testing those same calls only the set() promise resolves. The get() promise never resolves ("Exceeded timeout of 5000 ms for a test.[I tested with timeouts > 100000000]) The emulator receives the get() request without any problem.(It gets logged in the Request tab of the emulator)
This is a simple test which isolates my problem.
import { firestore } from '../firebase';
it('Gets from Firestore', async () => {
try {
await firestore.collection("users").doc("testUser").set({ name: "Frank" })
await firestore.collection("users").doc("testUser").get()
expect(1).toBe(1);
} catch (err) {
console.log(err)
}
})
Firestore initialization (creds not included):
import firebase from "firebase/app";
import 'firebase/firestore';
import 'firebase/auth';
const firebaseConfig = {
apiKey: "",
authDomain: "",
projectId: "",
storageBucket: "",
messagingSenderId: "",
appId: "",
measurementId: ""
};
firebase.initializeApp(firebaseConfig);
const firestore = firebase.firestore();
if (window.location.hostname === "localhost") {
firestore.useEmulator("localhost", 8080);
}
export {firestore}
export default firebase;