When snapshot testing a component I want to only test the component itself, not the actions, state or the connecting function that is in Redux. This is because I have tests for these functions in other places.
This messes up your code coverage because it expects that you test all functions.
For example:
export const EarningsInfo = ({ close }) => ( /* ... */ );
const mapStateToProps = _ => ({});
const mapActionsToProps = dispatch => ({
close: _ => dispatch(closeModal()),
});
export default connect(mapStateToProps, mapActionsToProps)(EarningsInfo);
Jest is expecting that you test
earningsInfomapStateToPropsmapActionsToPropsconnect
So if you have a simple test like this:
import { EarningsInfo } from '../components/EarningsInfo';
it('renders correctly', () => {
const tree = renderer.create(
<EarningsInfo close={ () => null } />
).toJSON();
expect(tree).toMatchSnapshot();
});
Code coverage reports that you are only testing 25% of the file. I am sure this is working as intended.
My question is two fold
- Am I correct in my thinking that
mapStateToProps,mapActionsToPropsandconnectshouldn't need to be tested. - Is there a way to ignore a function name in for coverage purposes?
EarningsInfocomponent as a named export (in addition to the default export of the connected component) and just test the rawEarningsInfocomponent. Then have a few integration tests that make sure things are wired together properly.