0

我在我正在测试的组件中使用样式化组件,它看起来像这样:

export const StyledCheckboxGroup = styled(CheckboxGroup)`
> .ant-checkbox-group-item {
display: ${props => (props.inline ? 'inline-block' : 'block')};
}
`

我有一个看起来像这样的测试:

it('renders an inline widget with the appropriate style rules', () => {
  const options = {
    enumOptions: [
      {
        value: 'one',
        label: 'One'
      },
      {
        label: 'Two',
        value: 'two'
      }
    ],
    inline: true
  }

  const wrapper = mount(<Checkboxes options={options} />)
  const item = wrapper.find(StyledCheckboxGroup)
  const subject = item.find('.ant-checkbox-group-item')
  expect(subject).toHaveStyleRule('display', 'inline-block')
})

我希望能够使用酶的底座来匹配我的造型规则。我有两个结果,subject断言的输出如下所示:

"Expected [object Object] to be a component from react-test-renderer, or a mounted enzyme component."

"But had an error, TypeError: Cannot read property '_renderedComponent' of undefined"

深入研究源代码,我发现:

const renderedComponent = received.node._reactInternalInstance._renderedComponent

是错误所在,它可以_reactInternalInstance在组件上找到 ,但不能找到_renderedComponent.

4

0 回答 0