firebase-functions-test | unit testing library for Cloud Functions | Authentication library
kandi X-RAY | firebase-functions-test Summary
kandi X-RAY | firebase-functions-test Summary
The firebase-functions-test is unit testing library for Cloud Functions for Firebase. It is a companion to firebase-functions.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of firebase-functions-test
firebase-functions-test Key Features
firebase-functions-test Examples and Code Snippets
Community Discussions
Trending Discussions on firebase-functions-test
QUESTION
I am trying to test a Cloud Function that interact with a Firestore database. I am following the documentation for testing my function using firebase-functions-test in online mode and mocha (https://firebase.google.com/docs/functions/unit-testing)
Since the function I want to test delete a document in a collection, I first created a fake document that I push to the db, inside my test. Then I called with the wrap my function to test. It's asynchronous, so it takes a bit of time.
What I want to verify is that the document has been correctly removed. But the call to get the document and then the assert is sometimes faster than my actual function doing the delete. I would like to add a small delay before doing the verification.
I tried to add a settimeout, but the test returns 'passed' without waiting for the code inside the timeout to run and checking the assert.
Here is my test. Any help would be greatly appreciated!
...ANSWER
Answered 2021-May-29 at 08:25I'm not really sure what the .wrap()
is. Does that return a promise?
If you want to use .setTimeout()
, you can try it this way:
QUESTION
I am using
- Node 14
- firebase functions-test: 0.2.3
- firebase-admin: 9.6.0
- firebase-functions: 3.13.2
- firebase tools: 9.10.0
I am trying to perform unit testing of my scheduled cloud function. my cloud functions is like this
...ANSWER
Answered 2021-Apr-17 at 02:23after reading github issue in here. I finally find the solution!
first, in your package.json , write your test script. my script is like this
QUESTION
I am using
- Node 14
- firebase-functions-test: 0.2.3
- firebase-admin: 9.6.0
- firebase-functions: 3.13.2
- firebase tools: 9.8.0
so I want to perform unit testing for my firestore trigger function using firebase cloud function, I read the steps from the documentation in here.
I want to perform unit test using Firebase Emulator
. so I assume I will initialize the SDK in offline mode. the documentation said that
If you would like to write completely offline tests, you can initialize the SDK without any parameters:
so I initialize it like this
...ANSWER
Answered 2021-Apr-06 at 19:00To use the offline mode you need to stub API calls like admin.initializeApp()
. See the example given at https://firebase.google.com/docs/functions/unit-testing#importing_your_functions
QUESTION
When I replace functions.auth.user().onCreate(async (user) => {
with functions.https.onRequest((req, res) => {
I end up getting the following error:
Parsing error: Unexpected token stripeslint
I get this error for strip.
ANSWER
Answered 2021-Apr-04 at 20:24There are two things you need to adapt in your code:
- Use the
async
keyword when declaring the HTTPS Cloud Function.functions.https.onRequest(async (req, res) => {...}
. - Correctly terminate your cloud function by using the promise version of the
create()
method. See https://firebase.google.com/docs/functions/terminate-functions for more details on this key aspect.
QUESTION
I am using the firebase cloud function to create order id for Razorpay for my Android app using 'call' function as shown below. But I am unable to upload the code-
...ANSWER
Answered 2021-Mar-04 at 09:29I think this is related with await
. Not sure why its not so clear in the error however, await
can be used inside asynchronous function (reference). So we have 3 options to correct (probably more, but giving 3 here):
- make function asynchronous adding the
async
keyword like this:
QUESTION
I am trying to execute test functions with the firebase emulators:exec, the emulators start up successfully but are unable to load the functions code because of the following error
...ANSWER
Answered 2021-Feb-23 at 00:31If I'm reading this correct your service account file is inside the src/
directory. But once your function is built, the compiled code gets deployed to the lib/
directory. There your relative path is no longer valid.
QUESTION
I have a data structure made this way:
- Posts(collection)
- UserId(document)
- Posts(collection)
- postDoc (document)
And I'm setting a cloud function to change all Posts(subcollection) documents upon a certain event, and in order to do so I'm using collectionGroup
queries:
This is how I set it up:
...ANSWER
Answered 2021-Feb-02 at 19:34The get()
method is asynchronous, so you either need to use then()
to get the querySnapshot
when the Promise returned by get()
is fulfilled, or use async/await
. More details on how to deal with asynchronous calls in this SO answer.
then()
QUESTION
While deploying my codes with firebase functions, I get an error as below. I am getting the error in both functions. I think the error is related to the crypto-ts library. It would be great if you could help. My app is an end-to-end encrypted messaging app.
My Typescript Codes:
...ANSWER
Answered 2021-Feb-02 at 17:19Seeing your package.json
file, it seems that you haven't installed the crypto-ts
package. We should see it under dependencies
.
Do npm install --save crypto-ts
in your functions
directory.
In addition, note what is indicated in the first lines of the log. functions: package.json indicates an outdated version of firebase-functions. Please upgrade using npm install --save firebase-functions@latest in your functions directory
.
QUESTION
I have a React web app with a Firebase backend created with NodeJS. I use Firebase Functions. My Firebase functions execute when I call them from either localhost or from Postman. But when I call the functions from my domain (moonio.io), they are not executed, and the only thing that happens is that I get my index.js file back. Therefore, I'm suspecting my problem to be caused by the rewrites in the hosting part of the firebase.json file (api address "https://europe-west3-cryptocurrency-tracker-moonio.cloudfunctions.net/api" getting rewritten to "/index.html")?
firebase.json
...ANSWER
Answered 2021-Jan-24 at 09:43After many hours I finally found out the problem(s).
- Need to add another rewrite to the firebase.json file for taking care of the api. All the requests to the api must go to the corresponding api function in Firebase functions, and all other requests will go to index.html, as per the requirement for single page applications. Thus, the rewrite part of firebase.json needs to look like this:
QUESTION
I am a relative noob with Firebase my first time using it and following along with a tutorial. The tutorial is a bit outdated and I have been fixing bugs as I have been going, but this one has got me completely stuck. I try to run a different functions that trigger when a document is created in certain collections. However, i get the following error:
Error
...ANSWER
Answered 2020-Jul-11 at 22:19I had the exact same problem, trying to deploy the exact same code as you and I was just able to get it to deploy properly.
If yours is the same issue as mine, this is where the problem is:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install firebase-functions-test
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page