reactjs - Shallow test component, complain about required props gotten from mapStateToProps and mapDispatchToProps -
i shallow test component, , know shallow test test 1 level deep. problem warnings because component requireing props received mapstatetoprops , mapdispatchtoprops. makes me want know how send props down shallow rendered component without duplicate methods. using jest , enzyme.
let's call component componenta wrapped in hoc connect of react-redux (assuming using there mapstatetoprops , mapdispatchtoprops in question). traditional way testing component is:
get wrapped component:
connecthave static property namedwrappedcomponent, out this:const extractedcomponent = componenta.wrappedcomponent;mock functions , props , pass normal props extracted component:
const wrapper = mount(<extractedcomponent connectfunctiona={mocka} ... />);test normal component! :)
Comments
Post a Comment