开玩笑地检查是否存在elements属性 [英] Jest check if an elements attribute exists

查看:1118
本文介绍了开玩笑地检查是否存在elements属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想开玩笑地检查以下svg路径元素是否包含属性d
<path id="TrendLine" fill="none" stroke="black" d="M170,28.76363636363638C170,28.76363636363638,221.46221083573664,189.150059910"></path> 如何使用玩笑来搜索元素中的特定属性?

I want to check with jest if the following svg path element contains the attribute d
<path id="TrendLine" fill="none" stroke="black" d="M170,28.76363636363638C170,28.76363636363638,221.46221083573664,189.150059910"></path> How do I use jest to search for specific attribute in an element?

推荐答案

您可以使用酶浅层方法渲染您的组件,然后检查path元素上的道具:

You can use enzyme's shallow method to render your component and then to check the props on the path element:

// 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');
});

这篇关于开玩笑地检查是否存在elements属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆