Last active
April 24, 2019 19:55
-
-
Save dadamssg/a7dd64f63b863d69eae1b0541d1197a6 to your computer and use it in GitHub Desktop.
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 as rtlRender} from 'react-testing-library' | |
function render ({foo = 'defaultFoo', doSomething = jest.fn()} = {}) { | |
const result = rtlRender(<MyComponent foo={foo} doSomething={doSomething} />) | |
return { | |
...result, | |
doSomething, | |
clickButton: () => fireEvent.click(result.querySelector('button')) | |
} | |
} | |
describe('MyComponent', () => { | |
test('something', () => { | |
const {getByTestId, doSomething, clickButton} = render() | |
// ... | |
}) | |
test('something else', () => { | |
const {getByTestId, doSomething, clickButton} = render({foo: 'customFoo'}) | |
// ... | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment