- [Instructor] We've been discussing the tools
and theory around writing tests.
Let's apply that knowledge by installing Jest.
Two steps are necessary for installation.
The first thing we need to do is use NPM to install Jest
to the project's dev dependencies.
Then, we'll edit package.json and add the definition
for the test script, which will just be jest.
Finally, we'll add an ESLint environment configuration
for Jest globals.
This isn't strictly required,
but it will reduce a number of false positives
from the linter.
Let's switch over to VS Code.
Open a terminal
and make sure you're in the project directory.
We're going to use NPM to install Jest
to the dev dependencies dash capital D.
Press Enter.
After a moment, Jest and its dependencies will be installed.
As we're using Jest for a test framework,
we're going to have to add it to the scripts.
In the Explorer, open up package.json.
Find the script section and then add a comma, new line,
and then a definition for test,
which will just be jest.
Save the changes.
Focus back on the terminal
and then let's run the new script.
NPM has a helper for tests
so you can just type NPM space test and press Enter.
We've got an error.
No tests found.
Technically correct, the best kind of correct.
The last thing we're going to do
is edit the ESLint configuration.
The completed version can be found in the exercise files
and the Solutions03_02 folder.
In the Explorer, select .ESLintrc.js.
Within the ENV section,
we're going to add a new property, jest, and set it to true.
So, add a trailing comma, new line, and then jest,
and we'll set that to true.
Save the file, then click on the X to close the file
along with package.json.
Jest is ready to go.
So, how do we go about writing unit tests?