@@ -20,7 +20,7 @@ And make sure to refer to it as TDD, short for test-driven development.
20
20
21
21
The acronym helps your credibility a lot more than it should.
22
22
23
- So let's learn how to write Cloud Functions with test-driven design !
23
+ So let's learn how to write Cloud Functions with test-driven development !
24
24
25
25
PAUSE FOR INTERSTITIAL
26
26
@@ -42,7 +42,7 @@ I may have five big, nasty integration tests, and I only want to run one at a ti
42
42
43
43
...and Jest makes that easy.
44
44
45
- What we're going for here is a red/green development cycle.
45
+ What we need to achieve is a red/green development cycle.
46
46
47
47
We write a failing test that imports our module and fails...
48
48
@@ -52,11 +52,11 @@ Then we write just enough code in the module under test to make the test pass...
52
52
53
53
...and we're in a "green" or passed state.
54
54
55
- Now rinse and repeat, writing expectations in your tests and regular code...
55
+ Now rinse and repeat, writing expectations in your tests and writing regular code...
56
56
57
57
...switching between "red" and "green" states, until the module is done.
58
58
59
- Once the module you're working on is working and all green, run all of your tests.
59
+ Once the module you're working on is all green, run all of your tests.
60
60
61
61
When your tests are all passing, you're good to commit your code to GitHub or wherever...
62
62
@@ -86,7 +86,9 @@ Basically, every Cloud Function that we write will be wrapped in a higher-order
86
86
87
87
...so make sure to drop that terminology in your next interview as well.
88
88
89
- So our higher-order wrapping function takes a context object as its one argument...
89
+ So we start with a higher-order wrapping function...
90
+
91
+ ...which takes a context object as its one argument...
90
92
91
93
...and that context object has attributes named `admin` and `environment`.
92
94
@@ -150,7 +152,9 @@ The actual act of setting our custom claim would not work without a real life us
150
152
151
153
Mocking means replacing real code with a fake function that does nothing.
152
154
153
- So now that our custom claims call is replaced with a mocked, we can write the rest of our test.
155
+ So now that our custom claims call is replaced with a mock...
156
+
157
+ ...we can write the rest of our test.
154
158
155
159
I've written a `test admin` utility to authenticate a new Firebase Admin SDK instance.
156
160
@@ -176,9 +180,9 @@ Our production environment doesn't have the `test dash` prefixes...
176
180
177
181
And if our tests fail to clean up after themselves, it'll be easy to spot the issue.
178
182
179
- Now back to the spec file...
183
+ ...and now back to the spec file...
180
184
181
- ...and you'll see that we'll add the `admin` and `environment` variables to a `context` object.
185
+ ...you'll see that we'll add the `admin` and `environment` variables to a `context` object.
182
186
183
187
Then we'll initialize two utility functions just for the purposes of this test.
184
188
@@ -196,13 +200,13 @@ You don't want to leave any old data lying around, because it could interfere wi
196
200
197
201
So we have two utility functions, `set custom claims by email` and `remove custom claims by email`.
198
202
199
- We'll pass in the `context` object into both so they can set and remove our data.
203
+ We'll pass the `context` object into both so they can set and remove our data.
200
204
201
205
Don't worry about the details of how these functions are working...
202
206
203
207
...because they're literally just setting and removing data from the Realtime Database.
204
208
205
- We still have some more set up to do, so stay strong and let's forge ahead!
209
+ We have more set up to do, so stay strong and let's forge ahead!
206
210
207
211
Next we'll import the actual function that we want to test.
208
212
@@ -214,7 +218,7 @@ I like to name my functions generically in my spec files...
214
218
215
219
...so I've named this function `Func` with a capital `F`.
216
220
217
- Now we'll initialize our Firestore database and set our settings.
221
+ Now we'll initialize our Firestore database and our Firestore settings.
218
222
219
223
And we'll need access to our `usersCollection` later, so we'll initialize it here too.
220
224
@@ -224,23 +228,23 @@ Every Jest test should be nested within one or more `describe` blocks.
224
228
225
229
You can nest `describe` blocks as much as you like.
226
230
227
- Jest provides `describe` as a global variable that you can use within any Jest spec file.
231
+ Jest provides `describe` as a global function that you can use within any Jest spec file.
228
232
229
- It also provides `beforeEach`, `afterEach`, `beforeAll` and `afterAll` as global variables .
233
+ It also provides `beforeEach`, `afterEach`, `beforeAll` and `afterAll` as global functions .
230
234
231
235
You can call these `before` and `after` functions within any `describe` block...
232
236
233
237
...in order to run some code before and after each 'it' block...
234
238
235
239
...or before and after all of the code in the `describe` block.
236
240
237
- `it` is another global variable from Jest that lets us write our actual tests.
241
+ `it` is another global function from Jest that lets us write our actual tests.
238
242
239
243
So we're going to do a bunch of setup in our `beforeEach` function...
240
244
241
245
...and a little cleanup in our `afterAll`.
242
246
243
- Before each test we're going to initiailze our `capital F Func` function...
247
+ Before each test we're going to initialize our `capital F Func` function...
244
248
245
249
...and assign it to a `lowercase f func` variable.
246
250
@@ -264,7 +268,7 @@ This is going to be a little disappointing.
264
268
265
269
See, we just need to define an `it` block and give it a name and a function.
266
270
267
- The first test is just to make sure that we got the right environment object.
271
+ The first test is simply to make sure that we got the right environment object.
268
272
269
273
I was fussing around with my environments, and this smoke test makes sure that my setup succeeded.
270
274
@@ -300,7 +304,7 @@ It's all available on `Full Stack Firebase dot com`.
300
304
301
305
The online written material is all free and the entire course is open-source.
302
306
303
- You'll need to pay a few buck for the full Udemy course...
307
+ You'll need to pay a few bucks for the full Udemy course...
304
308
305
309
...but it's the culmination of hundreds of hours of work on my part...
306
310
0 commit comments