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.

Writing your first Jest unit test

Writing your first Jest unit test

- [Male Speaker] Now that we know what and where to unit test, let's write some tests. Switch over to VS code. In the Explorer view, navigate to lib, then schema, right click and select new file. The name will be reservation.test.js. Press enter when complete. We'll start by including the file that we want to test, the reservation schema. Const reservation equals require and then the current directory, reservation, add a trailing semi-colon. And then a new line. Let's describe the test suite for what we're going to be testing using the describe function. So we're going to use describe and then single quote and then combine date time. Then I'm going to use an arrow function expression. The first test will be about valid input. Use the it function and then be descriptive about what's happening. Should return an ISO 86 01 date and time with valid input. Then an arrow function expression. Here's the given part.…

Contents