Skip to content

Instantly share code, notes, and snippets.

@tho-graf
Last active February 3, 2018 15:57
Show Gist options
  • Save tho-graf/95a0204b3736ced4f50b2d0050b6b817 to your computer and use it in GitHub Desktop.
Save tho-graf/95a0204b3736ced4f50b2d0050b6b817 to your computer and use it in GitHub Desktop.
Setup Function for Enzyme Tests
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