Skip to content

Instantly share code, notes, and snippets.

@goldhand
Created March 2, 2018 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goldhand/94b419dc7e7de27f430db0f14150fa06 to your computer and use it in GitHub Desktop.
Save goldhand/94b419dc7e7de27f430db0f14150fa06 to your computer and use it in GitHub Desktop.
Line break react component
/**
* @module {Function} components/Break
* @flow
*/
import * as React from 'react';
import {css} from 'emotion';
const style = css`
margin: 0;
padding: 0;
`;
const styleClear = css`
${style}
&::after {
content: '';
display: table;
clear: both;
}
`;
const Break = ({
line,
clear,
}: {
line?: boolean,
clear?: boolean,
}): React.Node => {
const className = clear
? styleClear
: style;
return (line
? <hr className={className} />
: <br className={className} />
);
};
Break.displayName = 'Break';
export default Break;
/**
* components/Break.spec.js
*/
import React from 'react';
import {shallow} from 'enzyme';
import Break from './Break';
const setup = propOverrides => {
const minProps = {};
const props = {
...minProps,
...propOverrides,
};
const output = shallow(<Break {...props} />);
return {
props,
output,
};
};
describe('<Break />', () => {
it('does not explode', () => {
// This will fail if component throws
const {output} = setup();
expect(output.exists()).toBeTruthy();
});
it('renders with <hr> when line=true', () => {
const {output} = setup({line: true});
expect(output.find('hr')).toBeTruthy();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment