firebase-mock
firebase-mock copied to clipboard
missing firebase.firestore.FieldPath
TypeError: firebase.firestore.FieldPath is not a constructor
i could work it around using the following code:
const proxyquire = require('proxyquire');
const { expect } = require('chai');
const { firestore: { FieldPath } } = require('firebase-admin');
const { MockFirebaseSdk, MockFirebase, MockFirestore } = require('firebase-mock');
const auth = new MockFirebase().autoFlush();
const firestore = new MockFirestore().autoFlush();
const firebase = MockFirebaseSdk(null, () => auth, () => firestore);
firebase.firestore.FieldPath = FieldPath;
firebase.initializeApp();
const addActivities = proxyquire('../addActivities', { 'firebase-admin': firebase });
but the queries are not working (they return empty) when using special characters in the field name/path, which is the main reason for using firebase.firestore.FieldPath
in the first place (reference). example:
firebase.firestore().collection('questions')
.where(new firebase.firestore.FieldPath('tags', 'A|B'), '==', true)
.limit(10)
.get();
collection data:
{
"1": {
"body": "body",
"choices": [
"a",
"b",
"c",
"d",
"e"
],
"tags": {
"A": true,
"A|B": true,
"A|B|C": true
}
}
}