Skip to content

Instantly share code, notes, and snippets.

@Rolilink
Created October 1, 2017 00:29
Show Gist options
  • Save Rolilink/8d26c62957f09c41f8389c638389e29f to your computer and use it in GitHub Desktop.
Save Rolilink/8d26c62957f09c41f8389c638389e29f to your computer and use it in GitHub Desktop.
import React from 'react';
import PropTypes from 'prop-types';
import ListGroup from 'react-bootstrap/lib/ListGroup';
export default class List extends React.Component {
static propTypes = {
renderListItem: PropTypes.func.isRequired,
items: PropTypes.arrayOf(PropTypes.any).isRequired,
className: PropTypes.string,
}
static defaultProps = {
className: '',
}
get listItems() {
const { items, renderListItem } = this.props;
return items.map(item => renderListItem(item));
}
render() {
return (
<ListGroup className={this.props.className}>
{this.listItems}
</ListGroup>
);
}
}
import React from 'react';
import { shallow } from 'enzyme';
import serializer from 'enzyme-to-json/serializer';
import List from '../List';
expect.addSnapshotSerializer(serializer);
const renderListItem = item => <div className="list-item" key={`list-item-${item}`}>{item}</div>;
describe('Common.List', () => {
it('should call itemRenderer to render items');
it('should render items', () => {
const items = [1, 2];
const list = shallow(<List renderListItem={renderListItem} items={items} />);
expect(list).toMatchSnapshot();
});
it('should not render items when empty', () => {
const items = [];
const list = shallow(<List renderListItem={renderListItem} items={items} />);
expect(list).toMatchSnapshot();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment