React-native-firebase: RNFirebase core module was not found natively on iOS

Created on 16 Oct 2017  ·  8Comments  ·  Source: invertase/react-native-firebase

Issue

I am experiencing an issue with Jest when trying to run my tests on a react native application. Currently I have the stock tests inside of the suite, but the code doesn't even reach there when I run npm test. Essentially, it says this:

    > [email protected] test /Users/Jarred/Desktop/Programming/CIS-350/GvMarketplace/gvmarket
    > jest

     FAIL  __tests__/index.android.js
      ● Test suite failed to run

        RNFirebase core module was not found natively on iOS, ensure you have correctly included the RNFirebase pod in your projects `Podfile` and have run `pod install`.

         See http://invertase.link/ios for the ios setup guide.
          Error: RNFirebase core module was not found natively on iOS, ensure you have correctly included the RNFirebase pod in your projects `Podfile` and have run `pod install`.

           See http://invertase.link/ios for the ios setup guide.
          at new FirebaseCore (node_modules/react-native-firebase/lib/firebase.js:32:7)
          at Object.<anonymous> (node_modules/react-native-firebase/lib/firebase.js:226:1)
          at Object.<anonymous> (node_modules/react-native-firebase/index.js:1:185)
          at Object.<anonymous> (src/components/browse.js:3:26)

     FAIL  __tests__/index.ios.js
      ● Test suite failed to run

        RNFirebase core module was not found natively on iOS, ensure you have correctly included the RNFirebase pod in your projects `Podfile` and have run `pod install`.

         See http://invertase.link/ios for the ios setup guide.
          Error: RNFirebase core module was not found natively on iOS, ensure you have correctly included the RNFirebase pod in your projects `Podfile` and have run `pod install`.

           See http://invertase.link/ios for the ios setup guide.
          at new FirebaseCore (node_modules/react-native-firebase/lib/firebase.js:32:7)
          at Object.<anonymous> (node_modules/react-native-firebase/lib/firebase.js:226:1)
          at Object.<anonymous> (node_modules/react-native-firebase/index.js:1:185)
          at Object.<anonymous> (src/components/browse.js:3:26)

    Test Suites: 2 failed, 2 total
    Tests:       0 total
    Snapshots:   0 total
    Time:        11.278s
    Ran all test suites.
    npm ERR! Test failed.  See above for more details.
  ```  

I don't really understand the issue or why this is breaking because the code itself is working fine and I have no issues using this library, but for some reason it breaks all of the tests. I am using it just on iOS right now since that's all we're worried about currently. So basically the code is working, but something is stopping it from reaching the test suite.

**Podfile**
# Uncomment the next line to define a global platform for your project
platform :ios, '9.0'

target 'gvmarket' do
  # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
  # use_frameworks!

  # Pods for gvmarket
pod 'Firebase/Core'

pod 'Firebase/Firestore'
pod 'Firebase/Messaging'
pod 'Firebase/Auth'
pod 'Firebase/Storage'


  target 'gvmarketTests' do
    inherit! :search_paths
    # Pods for testing
  end

end

target 'gvmarket-tvOS' do
  # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
  # use_frameworks!

  # Pods for gvmarket-tvOS

  target 'gvmarket-tvOSTests' do
    inherit! :search_paths
    # Pods for testing
  end

end

```

Forgive me if I've missed anything. All relevant and up to date files can be found here:

https://github.com/jparr721/GvMarketplace/tree/master/gvmarket

If you need any more information I should be available to respond.

Environment

  1. Application Target Platform: iOS
  1. Development Operating System: macOS Sierra 10.12.5
  1. Build Tools: Xcode
  1. React Native version: 0.47.2
  1. RNFirebase Version: 3.0.3
  1. Firebase Module: Database/Auth

Most helpful comment

Thi is resolve gist for jest test
https://gist.github.com/b437be0a8da3343d83e40e820bcfda11.git
Hope help you.

All 8 comments

@jparr721 Take a look at this issue for some pointers with how to get RNFirebase working with Jest: https://github.com/invertase/react-native-firebase/issues/162

I'll close this for now - please comment on #162 if you need any more help.

@Ehesp @Salakar note for us to add this to the documentation

https://rnfirebase.io/docs/v3.2.x/installation/ios

````
4) After installation you encounter an error like RNFirebase core module was not found natively on iOS.

Resolution

It's most likely you did not run pod update to get the latest pod versions
Run pod update
You should see updated versions of your pods installed
You may need to re-run pod install
````

@jparr721 I have faced the same problems and fixed by mocking react-native-firebase module.
https://medium.com/@rui.fernandes/react-native-jest-react-native-firebase-b5245d8ddd1

Thi is resolve gist for jest test
https://gist.github.com/b437be0a8da3343d83e40e820bcfda11.git
Hope help you.

Hello @chrchm

I tried your code but I got this error. TypeError: _reactNativeFirebase.firestore.collection is not a function. This is my simple code

import { firestore } from "react-native-firebase";
const collection = firestore.collection("category").doc("sample");

any idea why?

Hi @ccfiel

You aren’t mocking firebase properly.
When you mock a module, it’s like building it on a new white paper.
Therefore, you have to move every function, every variable you use on you code…

So, your code breaks at

import { firestore } from “react-native-firebase”;
const collection = firestore.collection(“category”).doc(“sample”);

and tells you that
_reactNativeFirebase.firestore.collection is not a function.

If you check your mock you can see that you just mocked firestore but inside that you didn’t mocked collection!

So, you have to mock you collection inside your firestore. ;)

Btw, collection is a CollectionReference so you have to mock it as a function and inside that collection you have to mock doc which is a DocumentReference so you also have to mock it as a function. Inside that you will have to mock every functions that you use further in your code with your variable collection. const collection = firestore.collection(“category”).doc(“sample”);

So I guess it would be something like this

firestore: jest.fn(() => {
            return {
                onNotification: jest.fn(),
                onNotificationDisplayed: jest.fn(),
                collection: jest.fn((collectionPath) => {
                  doc: jest.fn((documentPath) => {
                    //keep mocking here what you use with your collection variable
                  })
                })
            }
        }),

Hope it helps you ;)

@ruimfernandes thanks a lot! :)

thanks @ruimfernandes

Was this page helpful?
0 / 5 - 0 ratings