这是一个最小的示例(我只是为了阐述我的问题而已)
const useStyles = makeStyles({
root: {
width: 500,
height: 500,
background: ({isRead}) => isRead ? '#EA1D250D' : 'white', // <= I want to test this
}
});
function Notification(props) {
const classes = useStyles();
return <div className={classes.root}/>
}
如何按照background
的{{1}}规则测试两个分支?
我尝试用包装器访问它:
makeStyles
在上面的测试中, it('Renders correctly for unread messages', () => {
const wrapper = mount(<Notification isRead={true}/>);
// Now here how can I expect `background` to be `#EA1D250D`?
expect(wrapper.find('div').first().props().style).to.have.property('background', '#EA1D250D');
});
属性实际上是style
,因为样式是通过undefined
那么我有什么方法可以出于测试目的访问className
的样式规则?