Last active
February 3, 2018 15:57
-
-
Save tho-graf/95a0204b3736ced4f50b2d0050b6b817 to your computer and use it in GitHub Desktop.
Setup Function for Enzyme Tests
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
function setup(propOverrides = {}) { | |
const defaultProps = { | |
onChange: jest.fn(), | |
renderBlockContent: jest.fn(), | |
value: [{ content: 'Test 1' }, { content: 'Test 2' }] | |
}; | |
const mergedProps = { | |
...defaultProps, | |
...propOverrides | |
}; | |
const wrapper = mount( | |
<BlockCollection {...mergedProps} /> | |
); | |
return { | |
wrapper, | |
mergedProps, | |
blockAt: index => wrapper.find('Block').at(index) | |
}; | |
} | |
test('Should allow to expand blocks', () => { | |
const { blockAt } = setup(); | |
expect(blockAt(0).prop('expanded')).toEqual(false); | |
expect(blockAt(1).prop('expanded')).toEqual(false); | |
blockAt(1).simulate('click'); | |
expect(blockAt(0).prop('expanded')).toEqual(false); | |
expect(blockAt(1).prop('expanded')).toEqual(true); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment