primer-react
Version:
Primer react components
41 lines (36 loc) • 975 B
JavaScript
import renderer from 'react-test-renderer'
import enzyme from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'
enzyme.configure({adapter: new Adapter()})
/**
* Render the component (a React.createElement() or JSX expression)
* into its intermediate object representation with 'type',
* 'props', and 'children' keys
*
* The returned object can be matched with expect().toEqual(), e.g.
*
* ```js
* expect(render(<Foo />)).toEqual(render(<div foo='bar' />))
* ```
*/
export function render(component) {
return renderer.create(component).toJSON()
}
/**
* Get the HTML class names rendered by the component instance
* as an array.
*
* ```js
* expect(renderClasses(<div className='a b' />))
* .toEqual(['a', 'b'])
* ```
*/
export function renderClasses(component) {
const {
props: {className}
} = render(component)
return className ? className.trim().split(' ') : []
}
export function mount(component) {
return enzyme.mount(component)
}