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
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
Survey of Node.js testing frameworks5m 5s
-
(Locked)
Install Jest in a Node.js project2m 25s
-
(Locked)
What and where to unit test?4m 46s
-
(Locked)
Writing your first Jest unit test4m 36s
-
(Locked)
Running a test suite with Jest6m 5s
-
(Locked)
Testing asynchronous callbacks with Jest5m 42s
-
(Locked)
Writing callback test suites with Jest6m 32s
-
(Locked)
Testing promises with Jest7m 52s
-
(Locked)
Challenge: Test async/await with Jest49s
-
(Locked)
Solution: Test async/await with Jest2m 51s
-
-
-
-