sbatson5 / firestore-jest-mock

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

React Native Support #141

Closed hkaras19 closed 2 years ago

hkaras19 commented 2 years ago

Summary

Does this library support @react-native-firebase/firestore?

Basic example

I followed the setup instructions in the README for a react native project; however, I get the following error:

Error: You attempted to use a firebase module that's not installed natively on your iOS project by calling firebase.app().

This leads me to believe that the library does not support @react-native-firebase.

Motivation

It would be very helpful to apply this mocking to react native projects!

hkaras19 commented 2 years ago

Update - I am able to get most functionality running with the following workaround:

const db = {} const mockedFirestore = new FakeFirestore(db) jest.mock("@react-native-firebase/firestore", () => () => mockedFirestore)

However, this is unable to access methods that are called as parameters. For example, firestore().collection()... works fine, but firestore.FieldValue does not.

sbatson5 commented 2 years ago

I haven't personally used this for a react-native project (although I do have a RN project using firebase... we just don't have tests 😬 ). But this library does look for particular modules and we don't currently check for @react-native-firebase/firestore. I don't believe the API's are much different, but we could add support for that and investigate the FieldValue issue

sbatson5 commented 2 years ago

I opened a PR to address this if you have time to test https://github.com/Upstatement/firestore-jest-mock/pull/142