From the course: Node.js: Testing and Code Quality
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Challenge: Mock a successful reservation creation
From the course: Node.js: Testing and Code Quality
Challenge: Mock a successful reservation creation
(upbeat music) - [Instructor] In this chapter we learned about a number of different techniques for replacing and inspecting our code with Jest mocks. In lib/reservations.test.js we've tested creating a reservation in two different ways. But both have been testing what happens when validation fails. Your challenge is to update reservations.test.js and add a new test spec for successfully creating a reservation in the database. Of course, the test won't interact with the actual database so you'll have to mock that up. As a stretch goal also mock the validation in order to skip it as validation is tested elsewhere. When you're done check out one possible solution in the next video, see you in a moment.
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)
-
-