Im trying to make a test that a function gets all documents from firestore where documents user (id) and the users id match.
This is the function:
export const getUserDocs = async () => { const user = auth().currentUser; if (!user) { return Promise.reject('User is null'); } const array: Type[] = []; const snapshot = await firestore().collection('Collection') .where('user', '==', 'user.id') .get(); snapshot.forEach((entry) => { let obj: Type = { foo: entry.data().foo, bar: entry.data().bar, ... }; array.push(obj); }); return array;};
In runtime the query and function work like they should. But when I test it, it fails. When I debug the test, it returns all documents (from local test data), disregarding the 'where' query. Then when I loop the snapshot the test fails at the first property, and I get:
TypeError: entry.data is not a function
My test function:
it('getUserDocs loads users own docs from Firestore', async () => { const user = currentUser let requestedDocs = await getUserDocs(); await flushPromises(); expect(requestedDocs).toMatchObject(userDocs); });
If I test the same function without the where query, the test is successful.
Problem doesnt seem to be in the user either, because if I replace the where query with, for example:
.where('desc', '==', 'some existing desc')
The same error comes up.