I can't understand why some tutorials use react-test-renderer
with react-testing-library
,
As i understand, react-test-renderer
is a library that can create a pure object from a react component and convert it to json snapshot!
import TestRenderer from 'react-test-renderer';
function Link(props) {
return <a href={props.page}>{props.children}</a>;
}
const testRenderer = TestRenderer.create(
<Link page="https://www.facebook.com/">Facebook</Link>
);
expect(testRenderer).toMatchSnapshot();
Now, i can do the same with Testing library
:
import { render } from '@testing-library/react;
test('create link snapshot', () => {
const {container} =
render(<Linkpage="https://www.facebook.com/">Facebook</Link>);
expect(container.firstChild).toMatchSnapshot();
})
I really can't understand why i need to use react-test-renderer
along with testing-library
, what can react-test-renderer
do testing-library
can't?