Test Components in the Next.js Project with Jest and Enzyme- Part 1. Steps for the Environment setting

Introduction
Jest is one of the popular test libraries and it comes from Facebook. There are many resources for us to set the environment.
For CRA (create-react-app), there is a built-in jest testing and test script and we won't have to do advanced settings. However, it becomes complicated when trying to apply Jest to the Next.js project for testing React components.
This article includes the following topics.
- Prepare a Next.js project
- Install packages
- Initialize jest.config.js
- Initialize babel.config.js
- Create a test suite with the test case
- Wrap up
- Launch the test
Step 1. Prepare a Next.js project
You may have the following options.
- Create a Next.js project with the create-next-app commands
npx create-next-app testproject2. Turn the CRA project into the Next.js project
- Then create next.config.js manually if you need it
const nextConfig = {};
module.exports = nextConfig;Step 2. Install packages
- Install packages for babel and Enzyme
npm install --save-dev @babel/plugin-syntax-jsx @babel/plugin-transform-runtime @babel/preset-env @babel/preset-react babel-jest babel-plugin-transform-es2015-modules-commonjs babel-preset-es2015 enzyme enzyme-adapter-react-16 jest @babel/plugin-proposal-decorators- Install Jest globally
npm install jest -gStep 3. Initialize jest.config.js
- Create jest.config.js


