jest adn enzyme testing code example
Example 1: enzye check if it renders
describe('when x', () => {
it('check if child renders', () => {
const wrapper = shallow(<Parent />);
expect(wrapper.find(ChildComponentName).length).toEqual(1);
});
});
Example 2: react enzyme
// global config react and enzyme
import { configure } from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'
import { shallow, mount, render } from 'enzyme'
import renderer from 'react-test-renderer'
configure({ adapter: new Adapter() })
global.shallow = shallow
global.mount = mount
global.render = render
global.renderer = renderer