reactjs - jest snapshot testing nested redux "connected" components
In this case the best way is to test the Wrapper
on its own by just mocking User
import Wrapper from './Wrapper'
jest.mock('./User', () => 'User') // note that the path to user is relative the test file not to the Wrapper.js file.
This will replace User
with a simple component with name User
.
Just a small tweak to the answer provided by @andreas-köberle as it may produce the error: using incorrect casing. Use PascalCase for React components, or lowercase for HTML elements
To fix that if you want to mock a component it should return a fn. Example reflects multi word naming:
jest.mock('./User', () => () => 'UserThingStuff')
or to return an HTML element:
jest.mock('./User', () => 'user-thing-stuff')