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.
Writing callback test suites with Jest
From the course: Node.js: Testing and Code Quality
Writing callback test suites with Jest
- [Instructor] With this knowledge about testing asynchronous callbacks in mind, our application has a good candidate for our callback unit test. Within the schema is a validator that uses an asynchronous callback which returns an error and value. The validate method does not interact with a service, and it has a consistent signature and structure. Therefore, it's a perfect place to start testing callbacks. Let's write the validate callback test suite with Jest. Switch to VS Code. Go up to File, go to Open Recent, and navigate to wherever your Nadia project is. Before we write any code, take a look at what we're going to test. From the Explorer, choose lib, schema, and choose reservation.js. Scroll to the bottom. The validate method takes a callback as an argument. It then uses Joi, a validation library, to check the structure of a validation. I've destructured the output into separate variables for the error and…
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
-
-
-
-