1 00:00:00,240 --> 00:00:06,180 In this video as promised it'll be up to you to write a couple of new test cases for a couple of new 2 00:00:06,180 --> 00:00:07,290 functions. 3 00:00:07,350 --> 00:00:13,230 Now I'll be providing you with the functions you'll be testing those functions will live over in math 4 00:00:13,260 --> 00:00:19,580 dot J S and will write the test cases right inside of this file so to kick things off. 5 00:00:19,590 --> 00:00:23,050 Let's go ahead and grab the functions we'll be testing. 6 00:00:23,100 --> 00:00:31,350 You can find those over at links dot Meade dot I O forward slash node test. 7 00:00:31,350 --> 00:00:37,350 This is going to redirect us over to a get hub just just a little code snippet. 8 00:00:37,350 --> 00:00:43,290 This contains the two functions you'll be testing as well as the challenged comments outlining what 9 00:00:43,290 --> 00:00:44,510 I'd like you to do. 10 00:00:44,760 --> 00:00:51,920 What I'm gonna do is grab all 15 lines copy them to the clipboard and we'll be pasting them in math 11 00:00:51,930 --> 00:00:58,950 dot J S JUST BELOW THE calculate tip function that we created in the last lesson. 12 00:00:58,950 --> 00:01:01,760 So now we have three functions inside of here. 13 00:01:01,980 --> 00:01:05,730 And it's time to talk about what exactly I'd like you to get done. 14 00:01:05,880 --> 00:01:11,970 So the big picture goal is to test the temperature conversion functions up above 1 converts Fahrenheit 15 00:01:11,970 --> 00:01:16,220 into Celsius and the other converts Celsius into Fahrenheit. 16 00:01:16,290 --> 00:01:20,070 You'll be writing to test cases one for each function. 17 00:01:20,190 --> 00:01:26,130 So down below you need to start by exporting both functions from this file and loading them into our 18 00:01:26,130 --> 00:01:27,760 test suite file. 19 00:01:27,840 --> 00:01:34,760 Then you'll create those two tests should convert thirty two degrees Fahrenheit to zero degrees Celsius 20 00:01:34,760 --> 00:01:36,270 will be the first one. 21 00:01:36,420 --> 00:01:42,990 In that case you want to call this function with the correct Fahrenheit value and assert that you get 22 00:01:42,990 --> 00:01:45,990 the correct Celsius value back. 23 00:01:46,020 --> 00:01:52,680 The other one should convert zero degrees Celsius to thirty two degrees Fahrenheit is going to use this 24 00:01:52,680 --> 00:01:55,150 function Celsius to Fahrenheit. 25 00:01:55,260 --> 00:02:03,330 You'll pass in 0 as the Celsius temperature and assert using expect that you get back the number thirty 26 00:02:03,360 --> 00:02:04,730 two last up. 27 00:02:04,730 --> 00:02:12,020 You go ahead and run the test suite making sure that you're two new test cases show up and are passing. 28 00:02:12,180 --> 00:02:14,070 So take some time to knock that out. 29 00:02:14,070 --> 00:02:19,200 Don't forget to run the test suite and when you're done come back and click play 30 00:02:23,140 --> 00:02:24,040 how that go. 31 00:02:24,040 --> 00:02:29,600 Let's kick things off by exporting both of these functions down below alongside of calculate tip. 32 00:02:29,950 --> 00:02:33,310 So first up we have Fahrenheit to Celsius. 33 00:02:33,310 --> 00:02:40,540 Select it from my autocomplete list and then we also have Celsius to Fahrenheit autocomplete can't work 34 00:02:40,570 --> 00:02:42,640 if I don't start to type things correctly. 35 00:02:42,640 --> 00:02:48,580 There is the option we want and now we're actually going to head over to the test suite file itself 36 00:02:48,880 --> 00:02:51,870 load those in and write the test cases. 37 00:02:51,910 --> 00:02:54,660 So for me I'm going to take these challenge comments. 38 00:02:54,670 --> 00:02:59,060 Cut them out I'll remove the empty spaces and save this file. 39 00:02:59,200 --> 00:03:03,490 I'll bring the challenge comments over here so we can continue to work through it. 40 00:03:03,580 --> 00:03:10,030 Down below I can remove the Y test comment and replace it with the challenge ones. 41 00:03:10,060 --> 00:03:14,460 Now the first thing we have to do is make sure we do load those two functions in. 42 00:03:14,590 --> 00:03:22,660 So alongside of calculate tip I'll be grabbing Celsius to Fahrenheit as well as Fahrenheit 2 Celsius 43 00:03:22,960 --> 00:03:23,740 and down below. 44 00:03:23,740 --> 00:03:27,450 We're gonna set up those two test cases we'll just do one at a time. 45 00:03:27,910 --> 00:03:37,000 So first up a new test with the following name should convert 32 degrees Fahrenheit to zero degrees 46 00:03:37,030 --> 00:03:38,140 Celsius. 47 00:03:38,140 --> 00:03:41,740 We'll set up the function and for this one we'll be calling. 48 00:03:41,730 --> 00:03:43,720 Fahrenheit to Celsius. 49 00:03:43,720 --> 00:03:50,180 So right here const i can go ahead and create a variable like temp or something similar. 50 00:03:50,320 --> 00:03:57,480 And this will be the return value from what comes back from calling Fahrenheit 2 Celsius. 51 00:03:57,490 --> 00:04:03,580 The function we're actually trying to test now in this case I'll pass thirty two degrees in Fahrenheit 52 00:04:03,670 --> 00:04:10,600 in and I would expect to get zero degrees in Celsius back so I'll use expect to expect something about 53 00:04:10,600 --> 00:04:11,650 the temperature. 54 00:04:11,800 --> 00:04:16,700 Expecting that it equals using it to be the number zero. 55 00:04:16,720 --> 00:04:17,760 Perfect. 56 00:04:17,860 --> 00:04:23,260 Now we could add the second test case but let's go ahead and just run this one to make sure it's passing 57 00:04:23,260 --> 00:04:24,780 before we go any further. 58 00:04:25,090 --> 00:04:27,700 And if it is passing we'll move on to the second. 59 00:04:27,760 --> 00:04:29,300 Right here it is. 60 00:04:29,410 --> 00:04:34,060 So down below that means a another call to test providing the name. 61 00:04:34,060 --> 00:04:36,370 In this case it is in the other direction. 62 00:04:36,550 --> 00:04:44,800 So should convert zero degrees in Celsius to thirty two degrees in Fahrenheit and we'll set up our function 63 00:04:45,280 --> 00:04:46,120 right here. 64 00:04:46,120 --> 00:04:52,180 Once again we can create a variable like temp or temperature or result or whatever makes sense for you 65 00:04:52,690 --> 00:04:55,520 and then we'll call the function we're trying to test. 66 00:04:55,600 --> 00:05:04,310 That would be Celsius 2 Fahrenheit passing in the initial value of 0 and expecting the result of 32 67 00:05:04,330 --> 00:05:05,240 degrees. 68 00:05:05,260 --> 00:05:09,110 So right here I'm expecting something about the temperature. 69 00:05:09,250 --> 00:05:14,330 Expecting that it equals using to be the number thirty two. 70 00:05:14,390 --> 00:05:20,110 Now with this in place we can remove the challenge comments as the only thing left to do is run the 71 00:05:20,110 --> 00:05:22,260 test suite for the final time. 72 00:05:22,720 --> 00:05:23,950 So I will remove it. 73 00:05:24,070 --> 00:05:30,750 Save the file rerun the test sweet and hopefully we have for passing test cases. 74 00:05:30,820 --> 00:05:35,650 And right here we do so with those two new test cases in place. 75 00:05:35,650 --> 00:05:41,530 You were able to verify that these functions are working as expected and if the code was to ever be 76 00:05:41,530 --> 00:05:48,010 changed or refactor it in the future we would be notified if it broke the functionality because the 77 00:05:48,010 --> 00:05:51,090 test cases we created would fail. 78 00:05:51,100 --> 00:05:55,240 So now that we have this in place that's where we're going to stop for this video. 79 00:05:55,240 --> 00:05:59,610 So far in this section we've covered the very basics of testing. 80 00:05:59,650 --> 00:06:06,410 We've set up just we explored the assertion library and tested some relatively simple functions. 81 00:06:06,430 --> 00:06:12,190 And the next lesson we're going to continue on testing more advanced functions and focusing on testing 82 00:06:12,250 --> 00:06:15,150 the contents of the task manager app. 83 00:06:15,190 --> 00:06:16,390 I'm excited to get to that. 84 00:06:16,420 --> 00:06:19,220 So let's jump right in to the next lesson.