How to test React Redux application with Jest
https://grokonez.com/frontend/react/how-to-test-react-redux-jest-test-tutorial
How to test React Redux application with Jest
In this tutorial, we're gonna look at step by step to test React Redux application with Jest. This will apply on the application that we have built before.
Configure Jest and Babel for testing
-
Install
jest-cli
andbabel-jest
:yarn add jest-cli babel-jest
-
Open package.json, add
scripts
:{ ..., "scripts": { ..., "test": "jest" }, "dependencies": { "jest-cli": "22.4.3", "babel-jest": "22.4.3" } }
It helps us to run testing with cmd:
yarn test
.
For watching:yarn test --watchAll
-
Open .babelrc, add
"env"
:{ "presets": ..., "env": { "test": { "presets": [ "env", "react" ] } }, "plugins": ... }
Run cmd:
yarn install
.
Now, we can run test inside filename.test.js file.
In this tutorial, we will use Jest test()
, expect()
, .toBe()
and .toEqual()
methods.
For more functions and details, please visit: Jest API Reference.
https://grokonez.com/frontend/react/how-to-test-react-redux-jest-test-tutorial
Top comments (0)