【发布时间】:2019-08-23 05:49:00
【问题描述】:
我这辈子都无法让 Jest/Enzyme 与样式化组件完美搭配。
我正在安装一个组件,它会过滤掉 5 个最近发货的列表。
it("should have five shipments", () => {
const wrapper = shallow(<LastFiveShipments shipments={dummyProps.shipments} />);
wrapper.debug();
const styledList = wrapper.find("styled.ul");
expect(styledList).exists().to.equal(true);;
})
const LastFiveShipments = ({shipments}) => {
return (
<StyledList>
<h5>Last Five Shipments:</h5>
{
shipments.sort((a, b) => new Date(a.cargo_units[0].created_at) - new Date(b.cargo_units[0].created_at))
.filter((shipment, index) => index < 5)
.map((shipment, index) => <li key={index}>{shipment.reference}</li> )
}
</StyledList>
)
}
const StyledList = styled.ul`
padding: 1em;
margin: 0 10px;
background: #f0f0f0;
border-radius: 10px;
border: 1px solid #14374e;
margin: 1em 0;
& li {
text-align: center;
}
`;
styled.ul 是 displayName,find 没有运气选择它。
【问题讨论】:
标签: reactjs jestjs enzyme styled-components