Understanding snapshot testing
Snapshot testing is a useful way to test that there are no unwanted changes in your user interface (UI). Jest generates snapshot files when snapshot tests are executed. The next time tests are executed, the new snapshot is compared to the previous one. If there are changes between the content of the files, the test case fails, and an error message is shown in the terminal.
To start snapshot testing, perform the following steps:
- Install the
react-test-renderer
package. The--save-dev
parameter means that this dependency is saved to thepackage.json
file'sdevDependencies
part, and it is only used for development purposes. If you type thenpm install --production
command in the installation phase, dependencies in thedevDependencies
part are not installed. So, all dependencies that are only required in the development phase should be installed using the--save-dev
parameter, like this:npm install react-test-renderer --save-dev
- After...