DEV Community

loading...

Discussion on: Unit testing Firebase Firestore & Cloud Functions

Collapse
lucasgeitner profile image
Lucas Geitner • Edited

You can also use firestore simulator to have only local data and you don't need the mocking ;)

if (process.env.NODE_ENV !== 'test') {
admin = admin.initializeApp()
firestore = admin.firestore;
db = admin.firestore();
auth = admin.auth;
}

if (process.env.NODE_ENV === 'test') {
const firebasetest = require('@firebase/testing');
admin = firebasetest.initializeAdminApp({ projectId });
db = admin.firestore();
auth = admin.auth;
firestore = admin.firestore;
}

module.exports = { db, admin, firestore, auth };