我将一个项目从迷人转移到了情感。唯一缺失的拼图?测试。
在glamorous中,我可以找到带有如下选择器的元素:
$component.find('StyledComponent');
$component.find('StyledComponent[prop="value"]');
这不再起作用了。到目前为止我发现的最好方法是:
import StyledComponent from 'my/ui/StyledComponent';
$component.find(StyledComponent);
$component.find(StyledComponent).filter('[prop="value"]');
我喜欢前一种方式,因为它根本不需要导入组件。一些情绪成分是在文件中定义的,而不是导出它们。在这些情况下,它会更加冗长:
$component.find('div[className*="StyledComponent"]');
$component.find('div[className*="StyledComponent"][prop="value"]'); // or
$component.find('div[className*="StyledComponent"]').filter('[prop="value"]')
有没有更好的办法?谢谢阅读!