Last active
May 25, 2021 12:55
-
-
Save dirtyhenry/f5afb099b011e40e8e8e0c26180af118 to your computer and use it in GitHub Desktop.
React Component Test Template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ComponentProps, ReactNode } from 'react'; | |
import { Store } from 'common/store/test-utils/factories'; | |
import expectRenderError from 'test-utils/expectRenderError'; | |
import { fireEvent, renderWithHoc } from 'test-utils/helpers'; | |
import XXX from '..'; | |
type RenderComponentProps = { | |
props: Partial<ComponentProps<typeof XXX>>; | |
jsxToRender?: (props: ComponentProps<typeof XXX>) => ReactNode; | |
}; | |
describe('XXX', () => { | |
const renderComponent = (args: Partial<RenderComponentProps> = {}) => { | |
const { jsxToRender = (actualProps) => <XXX {...actualProps} />, props = {} } = args; | |
const store = Store.build(); | |
const actualProps: ComponentProps<typeof XXX> = { | |
// TODO: complete this: | |
// onSubmit: jest.fn().mockResolvedValue(null), | |
// onChange: jest.fn(), | |
...props, | |
}; | |
return { | |
...actualProps, | |
...renderWithHoc(jsxToRender(actualProps), { | |
store, | |
/** Uncomment if form: useFormStore: true, */ | |
}), | |
}; | |
}; | |
it('renders without crashing', () => { | |
const { container } = renderComponent(); | |
expect(container).toMatchSnapshot(); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
type Props = {}; | |
const XXX = (_props: Props) => { | |
return <div>TODO</div>; | |
}; | |
export default XXX; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment