codyswanner / Meme-Cataloger

Learning ReactJS and Django while building something that I want to use
1 stars 1 forks source link

Snapshot Tests #92

Closed codyswanner closed 1 month ago

codyswanner commented 3 months ago

Write the code for Jest to create snapshots of all the rendered components.

Top-Level modules

TopAppBar

LeftDrawer

ImageFrame

In almost all cases, the code will look something like this, where "Subject" is the component being tested:

import renderer from 'react-test-renderer';
import Subject from './Subject';

describe('Subject', () => {
    test('snapshot', () => {
        const tree = renderer
            .create(<Subject prop1={prop1} prop2={prop2}/>)
            .toJSON();
        expect(tree).toMatchSnapshot();
    });
});

Not sure if it is possible or appropriate to render only the test subject, not all it's children? Seems like rendering the entire tree below the component would be highly redundant if each component will be tested, and not particularly helpful for debugging.

codyswanner commented 3 months ago

TopAppBar snapshot committed in 0e0cf4d

codyswanner commented 3 months ago

App snapshot committed in 9e4343f

codyswanner commented 1 month ago

Going a different direction on this -- snapshots are not required or even appropriate for all components, and in fact are not recommended by MUI. Snapshot tests will be added as necessary and appropriate while writing other tests.