In this video as promised it'll be up to you to write a couple of new test cases for a couple of new
functions.
Now I'll be providing you with the functions you'll be testing those functions will live over in math
dot J S and will write the test cases right inside of this file so to kick things off.
Let's go ahead and grab the functions we'll be testing.
You can find those over at links dot Meade dot I O forward slash node test.
This is going to redirect us over to a get hub just just a little code snippet.
This contains the two functions you'll be testing as well as the challenged comments outlining what
I'd like you to do.
What I'm gonna do is grab all 15 lines copy them to the clipboard and we'll be pasting them in math
dot J S JUST BELOW THE calculate tip function that we created in the last lesson.
So now we have three functions inside of here.
And it's time to talk about what exactly I'd like you to get done.
So the big picture goal is to test the temperature conversion functions up above 1 converts Fahrenheit
into Celsius and the other converts Celsius into Fahrenheit.
You'll be writing to test cases one for each function.
So down below you need to start by exporting both functions from this file and loading them into our
test suite file.
Then you'll create those two tests should convert thirty two degrees Fahrenheit to zero degrees Celsius
will be the first one.
In that case you want to call this function with the correct Fahrenheit value and assert that you get
the correct Celsius value back.
The other one should convert zero degrees Celsius to thirty two degrees Fahrenheit is going to use this
function Celsius to Fahrenheit.
You'll pass in 0 as the Celsius temperature and assert using expect that you get back the number thirty
two last up.
You go ahead and run the test suite making sure that you're two new test cases show up and are passing.
So take some time to knock that out.
Don't forget to run the test suite and when you're done come back and click play
how that go.
Let's kick things off by exporting both of these functions down below alongside of calculate tip.
So first up we have Fahrenheit to Celsius.
Select it from my autocomplete list and then we also have Celsius to Fahrenheit autocomplete can't work
if I don't start to type things correctly.
There is the option we want and now we're actually going to head over to the test suite file itself
load those in and write the test cases.
So for me I'm going to take these challenge comments.
Cut them out I'll remove the empty spaces and save this file.
I'll bring the challenge comments over here so we can continue to work through it.
Down below I can remove the Y test comment and replace it with the challenge ones.
Now the first thing we have to do is make sure we do load those two functions in.
So alongside of calculate tip I'll be grabbing Celsius to Fahrenheit as well as Fahrenheit 2 Celsius
and down below.
We're gonna set up those two test cases we'll just do one at a time.
So first up a new test with the following name should convert 32 degrees Fahrenheit to zero degrees
Celsius.
We'll set up the function and for this one we'll be calling.
Fahrenheit to Celsius.
So right here const i can go ahead and create a variable like temp or something similar.
And this will be the return value from what comes back from calling Fahrenheit 2 Celsius.
The function we're actually trying to test now in this case I'll pass thirty two degrees in Fahrenheit
in and I would expect to get zero degrees in Celsius back so I'll use expect to expect something about
the temperature.
Expecting that it equals using it to be the number zero.
Perfect.
Now we could add the second test case but let's go ahead and just run this one to make sure it's passing
before we go any further.
And if it is passing we'll move on to the second.
Right here it is.
So down below that means a another call to test providing the name.
In this case it is in the other direction.
So should convert zero degrees in Celsius to thirty two degrees in Fahrenheit and we'll set up our function
right here.
Once again we can create a variable like temp or temperature or result or whatever makes sense for you
and then we'll call the function we're trying to test.
That would be Celsius 2 Fahrenheit passing in the initial value of 0 and expecting the result of 32
degrees.
So right here I'm expecting something about the temperature.
Expecting that it equals using to be the number thirty two.
Now with this in place we can remove the challenge comments as the only thing left to do is run the
test suite for the final time.
So I will remove it.
Save the file rerun the test sweet and hopefully we have for passing test cases.
And right here we do so with those two new test cases in place.
You were able to verify that these functions are working as expected and if the code was to ever be
changed or refactor it in the future we would be notified if it broke the functionality because the
test cases we created would fail.
So now that we have this in place that's where we're going to stop for this video.
So far in this section we've covered the very basics of testing.
We've set up just we explored the assertion library and tested some relatively simple functions.
And the next lesson we're going to continue on testing more advanced functions and focusing on testing
the contents of the task manager app.
I'm excited to get to that.
So let's jump right in to the next lesson.