Preparation conditions

Build on the directories and code created in the tutorial in Section 1. If you haven’t seen the first tutorial, follow me for previous articles in this series

This tutorial will focus on some of the command-line tools available in Jest. Copy the code from Section 1 and run the NPM run test:

First of all, explain these commands

Here a few commands everybody oneself must begin to try, ability can increase impression

Jest uses git to determine which files have been modified. Add a git repository as follows:

  • git initInitialize the Git repository
  • git add .Add all files to the staging area
  • git commit -m 'init'Submit the file to the local repository

The following are configured in package.json

–watchAll

We currently use –watchAll, which monitors all file changes to the script configuration of packeage.json files

"scripts": {
  "test": "jest --watchAll"
}
Copy the code

–watch

This has the same effect as using –watchAll and pressing the O key. Only retest the modified files each time

"scripts": {
  "test": "jest --watch"
}
Copy the code

–init

Generate a jEST base configuration file

–coverage

Exporting test coverage information as a report generates test coverage details a Coverage folder is generated in the project, and open index.html to view the details

The above several are more commonly used, in the actual project to master these several is enough, JEST CLI configuration file has a lot of, but in the actual development, we are with other scaffolding, out of the box, a lot of configuration I have not used, if you are interested, you can go to the official website documentsjestjs.io/docs/en/cli

This is a very small section, but it’s best to try it out for yourself to get a better impression and understanding of how to test asynchronous code in JEST

My ability is limited, the article may have incorrect or inappropriate parts, I hope you can point out

Pay attention to the public number, and I learn the front-end necessary skills, front-end automation test JEST