Skip to content
Advertisement

Is it is possible to test only one function from component with Jest?

I have react component, for example something like this:

JavaScript

And I’m trying to write test that should looks like this:

JavaScript

Can I mock useState, useContext and useLocation from <MyComponent/> and pass my custom data instead of real data from real component?

Advertisement

Answer

After deeper researching I’ve understood, that in such situation I can’t write test only for function in my component. So, I’ve created unit-test, that tests all my component, not only one function.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement