- We've already configured Jest to run through NPM test.
So let's execute our brand new tests.
Switch over to VS code,
open up a terminal,
and then type MPM test and press Enter.
The test suites run and we have a failure and a pass.
Let's look at the output.
I'm going to open up this window and then scroll to the top.
Right at the top, we see the name of the test suite by file
along with the overall pass or fail.
The implicit name of the suite is the file path,
lib schemareservations.test.js.
Under each file name comes the test suites defined.
We only created one with describe combined date time.
Under the name of the suite comes the individual test specs.
The first test with valid input failed,
which is indicated with a red X,
more on the failure and a moment.
At the end is the duration
of test execution in milliseconds.
The second test passed with a green check mark.
After the broad report of the passes and failures,
there's a breakdown of the failures.
Combined date time should have returned an ISO date and time
but it didn't.
Jest then breaks down what the test was supposed to do.
So expect received two equal expected,
with a note about deep equality for the type of comparison.
After the pseudo code version,
comes the highlighted comparison
of the expected and received.
It expected fail, but a received 2017.
We intentionally made this fail,
but the test doesn't know that.
Following the comparison
the position of the failed code is shown in context,
complete with character position and file name.
Finally, there's a summary report.
There's one failed test suite out of one total.
One test failed, one passed, and there were two total tests.
There were no snapshots,
which are a type of react UI testing.
The total time taken is shown in human readable format.
The second to last line describes the scope of execution
which in this case we ran all tests suites.
The last line is from NPM itself, not Jest.
It just says the test failed
and it doesn't know why so see above.
If we want to suppress the NPM message,
we can run MPM test with a space, dash dash, silent flag
and press Enter.
We get the same output
with a slightly different execution time.
This time it includes an estimated execution time as well
since it has a previous test to compare to.
Note that there isn't an NPM error
even though the test failed.
This can be useful when setting up continuous integration.
We can also execute just directly by using NPX.
So just type NPX space, jest and press Enter.
Practically it's the same output.
Let's fix that failing test.
If it's not already open,
make sure that you have reservation.test.js open.
The first thing we want to do
is only run the failing test spec
Just includes a method named .only.
.Only allows a subset of tests to be executed
either a specific test suite or spec.
There's a couple of different ways to use it.
With describe use dot only to execute
the suites marched with .only.
It and test are similar in syntax,
it only will only run the test specs marked with only.
For convenience, there's also an alias bit.
So instead of it, just add an F at the beginning
Edit the first it-statement to be it.only
so only this test spec runs.
So it.only save the change.
And let's try this out.
Switch over to the terminal.
Let's run NPM test, and then press Enter
The test run failed, but it only ran the one test.
It skipped the should return null test spec
and the report at the bottom shows one skipped to test.
Let's fix this failing test.
Back in the Editor, remove the .only
Then edit the expected fail online eight to be 2017.
Save the changes.
Switch back to the terminal,
where will execute with one more variation.
This time passing a flag to jest
which will only report failures and a summary.
We're going to use NPM space test,
then a space and then two dashes
to indicate that we're going to pass arguments to the script.
We'll then use the dash dash silent option to prevent tests
from printing messages through the console.
When ready press Enter.
This time, we have much more concise output
and everything past,
fantastic news.
To see more command line options for jest
type NPX jest space, dash dash help
A list of all available options are shown
along with the recommendation to see the documentation
at their website.
Let's clean up.
Close out, reservation.test.js
and kill the active terminal instance.
We've been testing synchronous code so far
but how do we test callbacks?