From the course: Node.js: Testing and Code Quality
Unlock the full course today
Join today to access over 24,400 courses taught by industry experts.
Solution: Mock a successful reservation creation
From the course: Node.js: Testing and Code Quality
Solution: Mock a successful reservation creation
(upbeat music) - [Instructor] Here's the solution to the challenge about mocking a successful reservation creation with Jest. If you haven't completed it yet, please take a moment to practice your skills. Switch over to VS code. In the Explorer, navigate to lib reservations.test.js. Scroll to describe create if it's not already visible. While we previously required reservations every time, we're going to be manipulating it prior to requiring it. So we're going to take the reservations require, paste those into the two test specs, and remove the before all. With that preparation out of the way, we can write our test spec for creating a reservation with no validation problems. At the end of the group, we're going to start with an it should create a reservation if there are no validation problems and this is an async function. Next, we're going to prepare to require. We'll start with something that we expect. So const…
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
-
-
-
-
-
-
(Locked)
Replacing code with test doubles6m 51s
-
(Locked)
Mocking functions for test code7m 1s
-
(Locked)
Writing your first Jest mock5m 46s
-
(Locked)
Mock an entire module with Jest7m 22s
-
(Locked)
Mocking module dependencies6m 19s
-
(Locked)
Spying to observe interactions7m 3s
-
(Locked)
Challenge: Mock a successful reservation creation53s
-
(Locked)
Solution: Mock a successful reservation creation6m 11s
-
(Locked)
-
-