sbatson5 / firestore-jest-mock

Jest Helper library for mocking Cloud Firestore
https://www.npmjs.com/package/firestore-jest-mock
178 stars 59 forks source link

Fetch document with full path doesn't work #14

Closed Philmod closed 4 years ago

Philmod commented 4 years ago

Description

When you fetch a specific document with full path, it doesn't find it from the mock database.

Steps to reproduce

mockFirebase({
  database: {
    'mycol/id/mysubcol': [
      { id: 'subId' },
    ],
})

const doc = await lib.db
        .doc(`mycol/id/mysubcol/subId`)
        .get()

But this one does work:

const doc = await lib.db
        .collection(`mycol/id/mysubcol`)
        .doc('subId')
        .get()

Expected result

The document from the database.

Actual result

No result.

Environment

sbatson5 commented 4 years ago

Thanks for pointing this out. The mock DB makes the assumption that you would call collection first (as that's what I was doing in my repo) but it should definitely support what you're trying.

Will take a look this week but PRs are definitely welcome too :)