Test React Component Props with Enzyme and Jest

InstructorTyler Clark

Share this video with your friends

Send Tweet

With our component rendered and our assertions testing our nodes, lets test our component’s props. We will use the shallow render methods .props and .prop to test that our component’s props are being passed through correctly. Next we’ll use .setProps to set new props within our components and test that our component handles them correctly.

Shazaib Ahmad
~ 6 years ago

Hi Tyler,

Am I right in thinking that the difference between wrapper.instance() and wrapper.props() is that the former is testing for more for the component itself (Link) and that it allows for a prop called address. Whilst the latter is just testing that children components can set a value for that prop? I was just a bit unclear on this!

Thanks!

dong cai
~ 6 years ago

Hi all, I found that React16 doesn't support wrapper.instance() which only returns null. How am I supposed to fix it?

Edit: Sorry my mistake, I just noticed that Stateless functional component does not support wrapper.instance();