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
From the course: Node.js: Testing and Code Quality
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.…
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
-
-
-
-