reactjs - Force Enzyme mount() to validate PropTypes -




i trying write jest tests using enzyme's mount() function ensures error thrown when bad data given react component, mount() performs proptypes validation first time mount() called. following test suite using improperly formatted props:

it('should throw "failed prop type" error', () => {         expect(globalnavigation).tothrow("failed prop type");     }); it('should throw "failed prop type" error', () => {         expect(globalnavigation).tothrow("failed prop type");     }); 

the first test passes, second fails because react not validating props. how can force mount() function validate proptypes?

your component receives props parent. therefore, should test parent component make sure passes right props children. should not test child component see if indeed given right props -- responsible faking props. because of that, highly suggest use shallow instead of mount.

defining proptype checks way developers warned during development might have forgotten pass props component. don't think should testing that... test in itself. proptypes check not supposed show in production.





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -