soumak77 / firebase-mock

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

missing firebase.firestore.FieldPath #139

Open cruzdanilo opened 5 years ago

cruzdanilo commented 5 years ago
TypeError: firebase.firestore.FieldPath is not a constructor
cruzdanilo commented 5 years ago

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
    }
  }
}