我把一个项目从魅力转移到了情感上。唯一遗失的拼图吗?测试。
在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"]')有没有更好的方法?感谢您的阅读!
发布于 2019-03-01 19:52:07
您仍然可以通过在定义样式组件时设置样式组件的displayName来使用第一种方法。
const StyledComponent = styled('div')` // ... `;
StyledComponent.displayName = 'StyledComponent';这将允许您在使用首字母的测试期间找到:
$component.find('StyledComponent');我希望这能帮到你。
https://stackoverflow.com/questions/54153985
复制相似问题