Closed satazor closed 4 years ago
The getTree functions that are in tests should not call render. The reason is simple: I would like to still use getTree when rerendering.
getTree
render
Instead, render should be called from the outside.
Moreover, we can make it more obvious we are rendering a react component like so:
import { render } from '@testing-library/react'; import Foo from './Foo'; const Tree = (props) => <Foo { ... props } />; it('should render correctly if X prop changed', () => { const { rerender } = render(<Tree foo="baz" />); // ... rerender(<Tree foo="baz" />); // .... });
This approach also makes it easier to test SSR when necessary:
import { renderToString } from 'react-dom/server'; it('should render correctly if X prop changed', () => { const html = renderToString(<Tree foo="baz" />); // ... });
The
getTree
functions that are in tests should not callrender
. The reason is simple: I would like to still usegetTree
when rerendering.Instead,
render
should be called from the outside.Moreover, we can make it more obvious we are rendering a react component like so:
This approach also makes it easier to test SSR when necessary: