Fireship · @fireship
Firestore Rules Testing with the Emulator - New Feature
Uploaded November 1, 2018 · Length 11:45
Summary
Learn how to test Firestore rules using the emulator and Jest, including setting up the emulator, writing test cases, and using helpers to make testing easier.
- firestore rules testing
- firebase emulator
- jest testing
- firebase security rules
- cloud firestore testing
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:00
[Music]
- 0:06
fire base summit wrapped up a few days
- 0:08
ago and although I wasn't able to make
- 0:09
it in person they did announce a bunch
- 0:11
of cool new features the feature that is
- 0:13
most exciting to me is the local
- 0:14
emulator for Fighter Store and the
- 0:16
real-time database the emulators allow
- 0:18
you to run an instance of your database
- 0:19
locally meaning you can build up a test
- 0:21
suite around your security rules
- 0:23
this not only speeds up development time
- 0:25
but it also increases the integrity of
- 0:27
your back-end security in today's video
- 0:29
you'll learn how to set up the emulator
- 0:30
and build out a full test suite using
- 0:32
chests if you're new here like and
- 0:34
subscribe and make sure to grab the full
- 0:36
source code from angular firebase comm
- 0:38
now before we get going with the
- 0:39
emulator I'd also like to point out that
- 0:41
firebase announced a new project
- 0:42
management API this API makes it
- 0:45
possible for apps to manage firebase
- 0:47
projects of other users for example you
- 0:49
can now deploy your firebase projects
- 0:51
directly from stack blitz or glitch but
- 0:53
the more exciting thing going on there
- 0:54
is that you can use this project
- 0:56
management API to build your own apps
- 0:58
that do the exact same thing so let me
- 1:00
know in the comments if you want to see
- 1:01
that covered in a future video so now
- 1:03
let's get started talking about the
- 1:04
emulator the emulator just runs fire
- 1:06
store or the real-time database locally
- 1:08
on your machine this means you can now
- 1:10
simulate interaction with the database
- 1:12
without actually having to run it in the
- 1:13
cloud this makes it so much easier to be
- 1:16
confident that a complex set of security
- 1:18
rules are working the way that they
- 1:19
should I'm gonna go ahead and set this
- 1:21
project up with just a vanilla
- 1:22
JavaScript and just as the testing
- 1:24
library the reason I choose jest is
- 1:26
because it's very developer friendly and
- 1:28
also really good at testing asynchronous
- 1:30
code to start testing your rules in
- 1:32
isolation
- 1:32
I'd recommend starting from a brand new
- 1:34
directory and then install the latest
- 1:36
version of firebase tools once that's
- 1:38
done you can run firebase init fire
- 1:40
store and that will pull in your
- 1:42
existing security rules from whichever
- 1:43
project you select from there you can
- 1:45
run NPM in it to set up a package.json
- 1:47
in this folder then after that we can
- 1:50
install our testing utilities which
- 1:51
include at firebase testing and jest
- 1:54
then we'll give us a directory structure
- 1:56
that looks something like this I've also
- 1:58
created a spec folder that includes our


