skip to Main Content

Similar to the question from here, I have upgraded to Expo 49 and now some of my Jest tests are failing with the following error:

TypeError: (0 , _auth(...).getReactNativePersistence) is not a function

For Jest tests, how do I make it so this error does not fail my tests?

The package.json includes the following relevant packages:

 "firebase": "^10.4.0",
 "expo": "~49.0.11",

With the following Firebase file:

import AsyncStorage from "@react-native-async-storage/async-storage";
import { initializeApp } from "firebase/app";
import { initializeAuth, getReactNativePersistence } from "firebase/auth";
import { getFirestore } from "firebase/firestore";
import { getStorage } from "firebase/storage";

// Your web app's Firebase configuration
const firebaseConfig = {...};

// Initialize Firebase
const app = initializeApp(firebaseConfig);
const auth = initializeAuth(app, {
  persistence: getReactNativePersistence(AsyncStorage),
});
const db = getFirestore(app);
const storage = getStorage(app);

export { auth, db, storage };

2

Answers


  1. Chosen as BEST ANSWER

    Okay got it... Add the following in your setup file:

        jest.mock('@firebase/auth', () => ({
      ...jest.requireActual('@firebase/auth'),
      getReactNativePersistence: () => console.debug('Initialized persistence ...'),
    }));
    

  2. @Shawn were you able to figure out the getReactNativePersistence issue?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search