用酶和玩笑测试makeStyles条件规则

时间:2020-03-05 10:10:48

标签: reactjs unit-testing jestjs enzyme chai

这是一个最小的示例(我只是为了阐述我的问题而已)

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的样式规则?

0 个答案:

没有答案
相关问题