Closed
Description
I have a component which should pass props through to it's child. What's the best way to verify this?
import React, { PureComponent } from 'react'
import classnames from 'classnames'
import styles from './styles.css'
export default class Box extends PureComponent {
render() {
const {
children,
className,
direction,
element: Elem = 'div',
...props
} = this.props
const _className = classnames([
className,
direction && styles[direction],
])
return (
<Elem className={_className} {...props}>
{children}
</Elem>
)
}
}
My current solution is to pass a data-
prop but feels like there should be a better way.
import _ from 'lodash'
import React from 'react'
import { render } from 'react-testing-library'
import Box from '../index'
test('pass through props', () => {
const { container } = render(
<Box data-my-custom-prop="my-custom-prop">
<div>foo</div>
</Box>,
)
expect(container.firstChild.dataset).toMatchSnapshot()
})
Metadata
Metadata
Assignees
Labels
No labels