[通常,当我使用Material-ui时,它的可扩展性妨碍了测试。
这是因为即使我正在使用,说:
const MyEventButton = () => (<IconButton />
<Event />
</IconButton>)
我在浅渲染的测试输出中得到的是:
<WithStyles(ForwardRef(IconButton)) >
<Event />
</WithStyles(ForwardRef(IconButton)) >
此HOC包装不是我在测试中过度关心的事情(即我正在[[not测试组件是WithStyles
或使用ForwardRef
]),因为这是一个实现细节,如果没有我,它可能会更改想要/需要更新测试。
it('Renders IconButton', () => {
const wrapper = shallow(<MyEventButton />);
expect(wrapper.exists('IconButton')).toEqual(true);
}
我必须做:
it('Renders IconButton', () => { const wrapper = shallow(<MyEventButton />); expect(wrapper.exists('WithStyles(ForwardRef(IconButton))')).toEqual(true); }
感觉就像我将测试与材料当前的内部工作紧密结合在一起。是否有一种方法可以在HOC内部进行对等并获取基本的Child组件?优选地,不必
dive
或猜测children().at(0)
在组件中的位置。出于类似原因,使用`wrapper.exists()也会失败。我看过Stackoverflow和互联网,却找不到可行的解决方案。