(upbeat music)
- [Instructor] Here's the solution to the challenge
about testing async/await promises with Jest.
If you haven't completed it yet
please take a moment to practice your skills.
Switch over to VS Code.
From the explorer open up lib
and select reservations.test.js.
Within the first it make the arrow function
expression async.
The setup is the same so we can skip down.
This is where the syntax gets a little difference.
We need to await, expect and then give it the function
that we're going to be awaiting,
which will be reservations.validate.
Then on the next line we'll use the .resolves matcher.
So expect knows that this is a promise
that it's going to resolve.
Resolves will chain to other matters
such as the existing .to equal
and then we're going to pass it or the reservation.
Just the single one and then add a semicolon.
Tidy up and remove any remaining old code.
For the rejection we're going to do the same thing
and make the arrow function expression async.
Since we're using shorthand, we don't need to specify
the number of assertions that we'll receive
so we'll just remove that.
Similar to the above, instead of returning
we're going to await and then expect
then parentheses reservations.validate reservation
and instead of resolves we're going to tab and then rejects
toBeInstanceOf error with a capital E.
Add a trailing semicolon and then clean up
and remove any old code.
Once you're all set, save the file.
Open up the terminal.
Let's make sure the tests still pass so NPM test.
Excellent all the tests suites passed.
Close out the terminal and any open editors.
The completed version can be found
in solutions/03_10/reservations.test.js.
Both forms of the asynchronous promise handling
like then and catch or with async/await
are functionally equivalent.
The difference is the style and the use of shorthand.
Which asynchronous testing syntax works best
for your project and team?