Daily Archives: 18.01.2018
Testing react’s dom with jest and enzyme
Install it like this: yarn add enzyme enzyme-adapter-react-16 —registry=»https://registry.npmjs.org»
Regression testing of react app with jest
Example is here — https://facebook.github.io/jest/docs/en/tutorial-react.html. The main idea is this: // Link.react.test.js import React from ‘react’; import Link from ‘../Link.react’; import renderer from ‘react-test-renderer’; test(‘Link changes the class when hovered’, () => { const component = renderer.create( Facebook, ); let tree = component.toJSON(); expect(tree).toMatchSnapshot(); // manually trigger the callback tree.props.onMouseEnter(); // re-rendering tree = component.toJSON(); …