Testing React Components with Jest
Rogers Kristen
1
describe('Todo component renders the todo correctly', () => {
it('renders correctly', () => {
const todo = { id: 1, done: false, name: 'Buy Milk' };
const rendered = renderer.create(
<Todo todo={todo} ></Todo>
);
expect(rendered.toJSON()).toMatchSnapshot();
});
});Here we are testing the full HTML tree.
I have the following components:
1.Text
2.Header composes Text component
3.Footer composes Text component
4.Container composes Header and Footer component
I am writing tests using .toMatchSnapshot() for all the components.
If i changed the Text component i have to update all the components snapshots. Is this correct ? I feel something wrong in this case. Any other solutions to test these kind of scenarios like shallow rendering or taking the snapshot of the particular component ?