Testing our first component with Jest and Enzyme
In this recipe, we are going to learn how to install and configure Jest in our project.
Getting ready
In this recipe, we need to install a few packages to test our React application:
npm install --save-dev jest jsdom enzyme enzyme-adapter-react-16 identity-obj-proxy
How to do it...
After we've installed Jest, we need to configure it:
- Add the
tests
scripts and the Jest configuration into ourpackage.json
:
{ "name": "react-pro", "version": "1.0.0", "scripts": { "clean": "rm -rf dist/ && rm -rf public/app", "start": "npm run clean & NODE_ENV=development BABEL_ENV=development nodemon src/server --watch src/server -- watch src/shared --exec babel-node --presets es2015", "start-analyzer": "npm run clean && NODE_ENV=development BABEL_ENV=development ANALYZER=true babel-node src/server", "test": "node scripts/test.js src --env=jsdom", "coverage": "node scripts/test.js src...