From the course: Node.js: Testing and Code Quality

Unlock the full course today

Join today to access over 24,700 courses taught by industry experts.

Solution: Test async/await with Jest

Solution: Test async/await with Jest

From the course: Node.js: Testing and Code Quality

Solution: Test async/await with Jest

(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…

Contents