DEV Community

Discussion on: How do we unit test functions within a functional component?

Collapse
 
joerter profile image
John Oerter

Instead of testing the function off of the component, I would recommend asserting against the rendered component. I recommend taking a look at react-testing-library and adopting it's approach to writing unit tests. I've been really happy with it in general.

Collapse
 
matenemeth profile image
Matt Nemeth • Edited

This^ . Also, if you have a function you reeeeally need to test, you can always extract it into a separate file/module/service/whatever, and you can unit test it separately from the functional component.