Skip to content

Instantly share code, notes, and snippets.

@kojinkai
Last active February 14, 2020 09:35
Show Gist options
  • Save kojinkai/7e10f2ad6642e480523552a36391c57f to your computer and use it in GitHub Desktop.
Save kojinkai/7e10f2ad6642e480523552a36391c57f to your computer and use it in GitHub Desktop.
Testing Boilerplate for a React Testing Library Test
import { render } from '@testing-library/react';
import React from 'react';
import Example from '../Example';
const defaultProps = {
someProp: 'someValue',
};
const setup = props => {
const propsWithDefaults = { ...defaultProps, ...props };
return render(<Component someProp={propsWithDefaults.someProp} />);
};
describe('The Example component', () => {
beforeAll(() => {
// configure mocks
});
afterAll(() => {
// tear down mocks to prevent leaking into other test suites
});
it('does things', () => {
const { debug } = setup();
debug();
});
it('does different things with other props', () => {
const { debug } = setup({ someProp: 'someOtherValue' });
debug();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment