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

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…

Contents