Closed devganiyahitesh1 closed 6 years ago
Since your cloud function seems to be making real database calls, you'll need to initialize the SDK in "online mode" as described in: https://firebase.google.com/docs/functions/unit-testing#initializing
hi @laurenzlong when i initialize in online mode i get the message that The default Firebase app does not exist
and i try to call admin.initializeApp()
in the test file and it says that The default Firebase app already exists
. in my index file when i have all my functions i have the admin.initializeApp()
and it works when i use npm run serve
@jfelipeara can you provide a code snippet of index.ts and the test file?
@thechenky i managed to make it work. The problem was that i was trying to call admin.firestore()
before importing my functions (index file) where the initialization was done. Thanks anyway!
@jfelipeara glad it works, thanks for the update!
firebase emulators:start --only firestore, functions
- results in an error
firebase emulators:start --only firestore
- no error
"firebase-functions-test": "^0.1.2", "firebase-admin": "~5.12.1", "firebase-functions": "^1.0.4",
I am creating unit test functions for cloud function which has firestore database operations and running functions locally. Normal functions without database operations are working fine but getting error in this case
Error sending message: { Error: The default Firebase app does not exist. Make sure you call initializeApp() before using any of the Firebase services.
Steps to reproduce `import {assert} from "chai" import as sinon from "sinon" import as test from "firebase-functions-test" import rp = require("request-promise-native"); import * as mocha from "mocha"
const fakeCreatingMessage = { id: "TEST-MESSAGE-ID", from: "Test from id", to: "Test to id", message: "my message", type: "text", create_at: "June 29, 2018 at 3:45:44 PM UTC+5:30", };`
And running this functions locally using
npm test
command. Myindex.ts
file already have added firebase-admin.import * as admin from 'firebase-admin'; admin.initializeApp()
Do i need to add below configurations to resolve above error ?
// At the top of test/index.test.js const test = require('firebase-functions-test')({ databaseURL: 'https://my-project.firebaseio.com', storageBucket: 'my-project.appspot.com', projectId: 'my-project', }, 'path/to/serviceAccountKey.json');