moxystudio / next-with-moxy

MOXY's boilerplate to accelerate the setup of new Next.js based web applications
https://next-with.moxy.tech
MIT License
101 stars 11 forks source link

Do not use `render` in getTree and friends #55

Closed satazor closed 4 years ago

satazor commented 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.

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" />);

    // ...
});