How do you install and set up Jest in a project?

Beginner

Answer

Jest can be installed via npm or yarn:

npm install --save-dev jest
# or
yarn add --dev jest

Basic setup in package.json:

{
  "scripts": {
    "test": "jest",
    "test:watch": "jest --watch",
    "test:coverage": "jest --coverage"
  }
}

For projects without Babel, you might need additional configuration for ES6+ syntax.