You must export the unbound component and test it separately (note the first export ):
export class Test extends React.Component { } ... export default connect( mapStateToProps )(Test)
During the test, you should test the rendering of an unconnected component (see curly braces around { Test } ):
import React from 'react'; import { shallow } from 'enzyme'; import toJson from 'enzyme-to-json'; import { Test } from './Test'; describe('...', () => { it('...', () => { const wrapper = shallow(<Test />) expect(toJson(wrapper)).toMatchSnapshot(); }) })
Hope this helps.
The mode specifically for your described case of the component should be:
import React from 'react'; import { connect } from 'react-redux'; export class Test extends React.Component { constructor(props) { super(props); } render() { return( <div className="here"/> ) } } const mapStateToProps = state => { return { barData: state.app.bar } } export default connect( mapStateToProps )(Test)
The test specification should be:
import React from 'react'; import { shallow } from 'enzyme'; import toJson from 'enzyme-to-json'; import { Test } from 'Test'; describe('Test component', () => { it('renders', () => { const wrapper = shallow(<Test />); expect(toJson(wrapper)).toMatchSnapshot(); }); });
What generates the following snapshot:
exports[`Test component renders 1`] = ` <div className="here" /> `;
source share