DEV Community

Samer Al-Saqqa
Samer Al-Saqqa

Posted on

Firebase Trigger Functions Testing with JEST and Emulators

In this 2 part video series, I will be sharing with you an approach through which you will be able to write tests using JEST and to assert results of side effects executed by Firebase cloud trigger functions locally on your machine without having to deploy to the cloud and/or to test online. We will be using JEST as a testing library and utilizing the Firebase emulators to serve an instance of our project on our machine.

[Part 1: Setup]
In this part we will be setting up our dev environment.

[Part 2: Writing Tests]
In this part we will be using the local Firebase Functions and Firestore emulators. Using Jest, we will execute a test routine which writes a document to the database and asserts the results of a trigger function copying that document to another collection.

You can download the project source code from Github:

Top comments (2)

morenomdz profile image

Thank you very much!

morenomdz profile image
MorenoMdz • Edited

I am having some issues syncing the trigger and the fetch, it looks like the trigger on the emulator is only running after the timeout set via the promise in the test...

Ok for some reason it is taking MUCH longer for my trigger to actually start, had to set a timeout of 15 seconds for it to sync...