您可以使用
enzyme's shallow method
要渲染组件,然后检查路径元素上的道具,请执行以下操作:
// at the top of your test file file:
import { shallow } from 'enzyme';
...
it('should render path element with the expected d attribute', () => {
// shallowly render your component:
const wrapper = shallow(<Component />);
// find the path element using a css selector
const trendline = wrapper.find('path#TrendLine');
// make assertion
expect(trendline.props()).toHaveProperty('d', 'M170,28.76363636363638C170,28.76363636363638,221.46221083573664,189.150059910');
});