Last active
February 14, 2020 09:35
-
-
Save kojinkai/7e10f2ad6642e480523552a36391c57f to your computer and use it in GitHub Desktop.
Testing Boilerplate for a React Testing Library Test
This file contains hidden or 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 { 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