1 00:00:01,060 --> 00:00:02,280 Instructor: We're now on to the very last step 2 00:00:02,280 --> 00:00:03,600 of our test right here. 3 00:00:03,600 --> 00:00:05,160 So we need to again 4 00:00:05,160 --> 00:00:07,170 get a reference to our textarea component 5 00:00:07,170 --> 00:00:10,560 and make sure that it has received the correct value. 6 00:00:10,560 --> 00:00:13,620 So to do so, we're again going to rely upon enzyme. 7 00:00:13,620 --> 00:00:16,500 Yes, we really rely upon enzyme 8 00:00:16,500 --> 00:00:18,930 when we are testing React components. 9 00:00:18,930 --> 00:00:20,580 So we're gonna very quickly go and look 10 00:00:20,580 --> 00:00:23,340 at some documentation on enzyme one last time, 11 00:00:23,340 --> 00:00:26,340 and we'll be able to write out our expectation right here. 12 00:00:26,340 --> 00:00:28,620 Now before we look at the enzyme documentation 13 00:00:28,620 --> 00:00:30,270 I wanna very quickly remind you 14 00:00:30,270 --> 00:00:32,523 that inside of our CommentBox component, 15 00:00:33,390 --> 00:00:35,610 we have our textarea right here. 16 00:00:35,610 --> 00:00:37,470 And what we're really trying to test 17 00:00:37,470 --> 00:00:39,510 inside this test that we're working on right now 18 00:00:39,510 --> 00:00:41,550 is making sure that that textarea 19 00:00:41,550 --> 00:00:45,030 receives the correct value prop. 20 00:00:45,030 --> 00:00:46,530 That's key right here. 21 00:00:46,530 --> 00:00:49,770 It's the value prop that you and I really care about. 22 00:00:49,770 --> 00:00:52,020 Is if we pass in the correct value prop right here 23 00:00:52,020 --> 00:00:54,270 then we know that React is going to essentially take it 24 00:00:54,270 --> 00:00:57,210 from there, and definitely show that correct input 25 00:00:57,210 --> 00:00:58,503 inside that textarea. 26 00:00:59,760 --> 00:01:02,340 So rather than saying that we want to figure out 27 00:01:02,340 --> 00:01:04,530 what value the textarea has, 28 00:01:04,530 --> 00:01:06,720 it might be a little bit more accurate to say 29 00:01:06,720 --> 00:01:08,220 that we want to verify 30 00:01:08,220 --> 00:01:12,300 that the textarea received the correct value prop. 31 00:01:12,300 --> 00:01:13,680 So with that in mind, 32 00:01:13,680 --> 00:01:17,580 if we flip back over to our enzyme documentation, 33 00:01:17,580 --> 00:01:21,870 again underneath our Full DOM Rendering section right here, 34 00:01:21,870 --> 00:01:26,870 we can find a method called, there we go, prop with key. 35 00:01:28,830 --> 00:01:31,470 So the prop function right here allows us 36 00:01:31,470 --> 00:01:33,630 to pull the prop that is passed 37 00:01:33,630 --> 00:01:36,240 to any element within our component. 38 00:01:36,240 --> 00:01:39,270 So you and I can find that textarea element, 39 00:01:39,270 --> 00:01:41,400 and then we can call the prop method on it 40 00:01:41,400 --> 00:01:43,740 and ask it to retrieve the value prop 41 00:01:43,740 --> 00:01:45,060 that was assigned to it. 42 00:01:45,060 --> 00:01:48,630 And that should retrieve the string that we had passed 43 00:01:48,630 --> 00:01:50,070 right here. 44 00:01:50,070 --> 00:01:52,800 So then we can write out a simple expectation and say, 45 00:01:52,800 --> 00:01:56,850 yes, we passed in the correct value of this.state.comment. 46 00:01:56,850 --> 00:01:57,720 So that's the idea, 47 00:01:57,720 --> 00:02:00,570 that's how we're going to actually test out our textarea. 48 00:02:00,570 --> 00:02:03,750 We're going to pull a prop off it and make sure we passed in 49 00:02:03,750 --> 00:02:04,983 the correct prop. 50 00:02:06,540 --> 00:02:09,289 So I'm gonna flip back over to my CommentBox test file. 51 00:02:10,380 --> 00:02:12,300 And then right down here, we'll write out 52 00:02:12,300 --> 00:02:13,950 our full expectation. 53 00:02:13,950 --> 00:02:17,040 So we're going to expect that, 54 00:02:17,040 --> 00:02:21,540 excuse me, not component but wrapped.find textarea. 55 00:02:21,540 --> 00:02:23,520 So we're going to get a brand new reference 56 00:02:23,520 --> 00:02:25,053 to our textarea element. 57 00:02:26,070 --> 00:02:28,950 Then we're going to pull off the prop of value. 58 00:02:28,950 --> 00:02:30,720 'Cause that's the name of the prop that we passed 59 00:02:30,720 --> 00:02:31,653 to that element. 60 00:02:32,867 --> 00:02:34,710 And then finally, outside of both sets 61 00:02:34,710 --> 00:02:36,000 of parentheses right here, 62 00:02:36,000 --> 00:02:37,890 we're gonna do a toEqual 63 00:02:37,890 --> 00:02:40,740 and we're gonna make sure that that prop value right there 64 00:02:40,740 --> 00:02:43,140 equals the string, new comment. 65 00:02:43,140 --> 00:02:44,730 'Cause that's what we had tricked our component 66 00:02:44,730 --> 00:02:47,490 into thinking the user had entered. 67 00:02:47,490 --> 00:02:49,860 I'm gonna really quickly give myself some space here, 68 00:02:49,860 --> 00:02:53,073 and I'm gonna say toEqual new comment, like so. 69 00:02:54,960 --> 00:02:56,370 So that's it for the test. 70 00:02:56,370 --> 00:02:58,050 I'm gonna save this test file, 71 00:02:58,050 --> 00:03:00,180 and I'll flip back over to my terminal, 72 00:03:00,180 --> 00:03:02,343 and it looks like that new test is passing. 73 00:03:03,360 --> 00:03:06,030 Now as usual, let's make sure that we make this test fail. 74 00:03:06,030 --> 00:03:08,370 And I just realized, I think we skipped that step 75 00:03:08,370 --> 00:03:09,690 on our last test as well. 76 00:03:09,690 --> 00:03:12,270 So let's make both these fail very quickly. 77 00:03:12,270 --> 00:03:13,440 So on the test up here, 78 00:03:13,440 --> 00:03:17,883 I will say toEqual 2 on both those tests. 79 00:03:18,720 --> 00:03:20,370 And then on the test we just put together, 80 00:03:20,370 --> 00:03:22,110 I'm gonna say toEqual 81 00:03:22,110 --> 00:03:24,363 about just some random string, like so. 82 00:03:25,200 --> 00:03:27,300 So now if I save this file and flip back over, 83 00:03:27,300 --> 00:03:30,060 I will expect to see all three of those tests failing. 84 00:03:30,060 --> 00:03:32,160 Or all three of those expectations really. 85 00:03:33,450 --> 00:03:37,380 So now on has a text area that users can type [Interviewer], 86 00:03:37,380 --> 00:03:39,780 we expected to see that gibberish right there 87 00:03:39,780 --> 00:03:43,110 but we actually got the string new comment, which is great. 88 00:03:43,110 --> 00:03:46,563 And then up here, has a text area and a button. 89 00:03:48,420 --> 00:03:51,360 In a, essentially, we said that we expected two 90 00:03:51,360 --> 00:03:54,690 but we actually received one button or text area. 91 00:03:54,690 --> 00:03:55,523 So awesome. 92 00:03:55,523 --> 00:03:57,270 It looks like our tests are working correctly. 93 00:03:57,270 --> 00:03:58,320 I'm gonna flip back over 94 00:03:58,320 --> 00:04:01,830 and change these all back to the correct values. 95 00:04:01,830 --> 00:04:04,683 And I'll do my toEqual of new comment as well. 96 00:04:06,330 --> 00:04:07,770 So one more time, I'll make sure everything 97 00:04:07,770 --> 00:04:10,740 is still passing, and we're great. 98 00:04:10,740 --> 00:04:12,930 Cool, so I think that's it for this test right here. 99 00:04:12,930 --> 00:04:14,310 Let's continue on the next section 100 00:04:14,310 --> 00:04:15,990 and I think we got one more test 101 00:04:15,990 --> 00:04:17,519 around our CommentBox component. 102 00:04:17,519 --> 00:04:19,470 So we'll take care of it in that video.