- Are projects now has just installed and is good to go.
Time for us to start adding some tests to our application,
starting with string tests.
Just our sessions make use of matches to compare
the output of our code to expected results.
So we'll be using string matches to test out
strings in this video.
To follow along with this video,
you need the 02 underscore 02B branch of the project
so make sure you're on the 02 underscore 02B branch.
For the exercises in this chapter,
we will be placing all our tests inside a special just
folder named tests, with double underscores on both sides.
When we run our test command, just look at this folder
and run the files inside it as test suits.
Let's go ahead and create a folder inside the source folder.
Next, create a strings dot JS file within this folder.
The file just created will continue our string tests.
Given tests and terminologies,
this file is known as it test suit.
Within the file, let's add a simple string test that
will test if a certain phrase contains a substring.
So here we start by writing the test case definition,
then within the test case we search the phrase
it's raining cats and dogs
to contain the substring dogs.
We do this using the expect function given to us by just
and distinct matcher to match.
Too much text in a regular expression or string
match in the search term.
Let's go ahead and save this file
then switch to the command line to run the test.
Now we're going to test command at the root of the project.
To run the string test we'll just add it.
The command we just ran invokes just to begin searching
the project for test files and any file found will be run
and the test results printed.
This process can sometimes take a while depending on
the number of tests, the logic in the test
or the speed of your machine.
Not only the testing process is complete
we see a passed result printer to the screen.
That is because the substring dogs does exist in the tested
phrase it's raining cats and dogs.
Just indicates a check mark to the left of the
test case name to show its status.
It also reports how many test cases and test suits that were
involved in the testing process and how many of them passed.
We also get information on how long
it took the tests to run.
Let's cause the test to fail by searching for a
non-existent substring and see how just
will post the failure.
Back in the text editor,
let's replace the search term by switching dogs to fishes
in the to match function then save the file.
Switch back to the terminal and run the test once again.
The test results are way different this time.
The red ink already indicates to us that something is
wrong somewhere and we know why.
The substrings fishes cannot be found in the given phrase.
And as you can see, just clearly we post that
expected button cannot be found in received string.
Just goes a step further by showing us where in the
test case the error is coming from.
In this case, it's in the substring supplied to the matcher.
We also get to use your stats on the number of tests
and field versus past test report,
including the time it took the test to run.