1 00:00:01,110 --> 00:00:01,943 Instructor: In the last section 2 00:00:01,943 --> 00:00:04,560 we put together a test around our comments reducer. 3 00:00:04,560 --> 00:00:06,840 At the very end of the video, I made a small change 4 00:00:06,840 --> 00:00:08,880 to the test to make sure that the test failed 5 00:00:08,880 --> 00:00:12,240 and it looked like it did in fact fail the way I expected. 6 00:00:12,240 --> 00:00:13,260 So I'm now gonna go back over 7 00:00:13,260 --> 00:00:16,590 to my test file and restore it to its working state. 8 00:00:16,590 --> 00:00:17,423 Cool. 9 00:00:18,480 --> 00:00:20,910 Now if I go back to my list of tests, I wanna write 10 00:00:20,910 --> 00:00:22,470 remember we also wanted to make sure 11 00:00:22,470 --> 00:00:24,300 that if we call the reducer 12 00:00:24,300 --> 00:00:27,120 with an action that has an unknown type 13 00:00:27,120 --> 00:00:28,830 we should not see an error 14 00:00:28,830 --> 00:00:31,320 or nothing should really just go wrong. 15 00:00:31,320 --> 00:00:33,510 So this test will be pretty straightforward. 16 00:00:33,510 --> 00:00:35,280 I'm gonna add in another it statement 17 00:00:35,280 --> 00:00:38,220 inside my test file and I'll give it a description 18 00:00:38,220 --> 00:00:41,830 of something like, handles action with unknown 19 00:00:43,740 --> 00:00:44,573 type. 20 00:00:48,390 --> 00:00:49,440 So in this case, 21 00:00:49,440 --> 00:00:54,030 we can write an even more terse test than we did previously. 22 00:00:54,030 --> 00:00:58,890 All we really have to do is call our comments reducer. 23 00:00:58,890 --> 00:01:01,020 We can pass in an initial state if we want to 24 00:01:01,020 --> 00:01:03,120 but we definitely don't have to. 25 00:01:03,120 --> 00:01:05,970 And then we can pass in an action that does not 26 00:01:05,970 --> 00:01:09,000 even have to have a payload or a tight property. 27 00:01:09,000 --> 00:01:12,840 So passing in an empty object essentially counts as passing 28 00:01:12,840 --> 00:01:17,460 in an action with an unknown type because it has no type. 29 00:01:17,460 --> 00:01:19,050 If you wanna be a little bit more explicit, 30 00:01:19,050 --> 00:01:20,460 you could always pass in 31 00:01:20,460 --> 00:01:23,250 an actual type property with some random string here. 32 00:01:23,250 --> 00:01:24,270 It's totally up to you. 33 00:01:24,270 --> 00:01:26,010 Really, both of them are more 34 00:01:26,010 --> 00:01:27,780 or less the same way of testing this reducer. 35 00:01:27,780 --> 00:01:29,480 You can really take it either way. 36 00:01:31,470 --> 00:01:34,080 So then all we have to do here is probably 37 00:01:34,080 --> 00:01:36,870 take whatever gets returned from comments reducer. 38 00:01:36,870 --> 00:01:38,320 I'll again call it new state. 39 00:01:40,380 --> 00:01:42,120 And then I'll write an expectation to say 40 00:01:42,120 --> 00:01:45,180 that new state should simply be an empty array. 41 00:01:45,180 --> 00:01:47,070 So we're just gonna kinda make the case to say, 42 00:01:47,070 --> 00:01:47,903 Hey, you know what? 43 00:01:47,903 --> 00:01:49,860 Comments reducer did not throw an error 44 00:01:49,860 --> 00:01:51,570 and as usual as expected, 45 00:01:51,570 --> 00:01:54,420 it's just gonna return whatever state it was provided 46 00:01:54,420 --> 00:01:55,970 which should be an empty array. 47 00:01:56,820 --> 00:02:01,820 So I'll say expect new state to equal empty array, 48 00:02:02,340 --> 00:02:03,810 like so. 49 00:02:03,810 --> 00:02:05,520 And that's pretty much it. 50 00:02:05,520 --> 00:02:09,300 Honestly, these kind of unknown action type tests right here 51 00:02:09,300 --> 00:02:10,380 you can definitely do them. 52 00:02:10,380 --> 00:02:12,420 I personally don't find them the most useful thing 53 00:02:12,420 --> 00:02:13,253 in the world. 54 00:02:13,253 --> 00:02:15,090 I think it's a lot more useful to write tests 55 00:02:15,090 --> 00:02:18,630 around actual action types that you know are going to come 56 00:02:18,630 --> 00:02:19,803 across the reducer. 57 00:02:20,910 --> 00:02:22,140 All right, so we'll flip back over 58 00:02:22,140 --> 00:02:23,700 to our test suite really quick 59 00:02:23,700 --> 00:02:26,280 and just make sure this is passing as well. 60 00:02:26,280 --> 00:02:28,260 And it looks like we're good to go. 61 00:02:28,260 --> 00:02:30,330 Now this is one case where I won't make you try to 62 00:02:30,330 --> 00:02:31,740 make the test fail here 63 00:02:31,740 --> 00:02:34,290 cuz it's kind of hard to make this test fail. 64 00:02:34,290 --> 00:02:36,240 So if you wanna give it a try, go for it. 65 00:02:36,240 --> 00:02:38,670 Otherwise, let's continue in the next section 66 00:02:38,670 --> 00:02:41,310 and we'll start writing some tests around the next part 67 00:02:41,310 --> 00:02:43,020 of our application, which will be our 68 00:02:43,020 --> 00:02:44,883 SaveComment action creator.