简体   繁体   English

使用Jest和React-test-renderer测试伪类

[英]Test for pseudo class using Jest and React-test-renderer

I have a few hover pseudo classes in css and want to run a test and check if they are behaving properly. 我在CSS中有一些悬停伪类,并且想要运行测试并检查它们的行为是否正确。 Is this possible with Jest? 笑话有可能吗? Apologies for my lack of knowledge here I'm only a day in using Jest. 抱歉我缺乏知识,在这里我只用Jest一天。

Css: CSS:

.my-btn--lg.my-btn--brand.hover, .my-btn--md.my-btn--brand:hover {
    background-color: #ac0000;
}

Seems it's impossible. 似乎不可能。

I'm not sure if jsdom provides appropriate version of window.getComputedStyle but anyway there is no way to check for styles based on pseudoclass so far. 我不确定jsdom是否提供了适当版本的window.getComputedStyle但是到目前为止,仍然没有办法检查基于伪类的样式。 jest as generic test runner and react-test-renderer that "just" compiles JSX into HTMLElements knows nothing about pseudoclass/hover state. 作为通用测试运行程序和react-test-renderer jest ,“只是”将JSX编译为HTMLElements对伪类/悬停状态一无所知。

See also https://stackoverflow.com/a/11495671/2071697 for details how you can parse CSS by yourselves to find :hover rule(but I believe it is not efficient way to compose unit tests) 另请参阅https://stackoverflow.com/a/11495671/2071697 ,了解如何自行解析CSS以查找:hover规则的详细信息(但我认为这不是编写单元测试的有效方法)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Jest和react-test-renderer使用Material-UI时,为什么我的渲染器失败? - Why is my renderer failing when using Material-UI using Jest and react-test-renderer? 为什么此测试使用Jest和react-test-renderer引发错误,因为它试图解析.graphql文件? - Why is this test using Jest & react-test-renderer throwing error because it's trying to parse a .graphql file? 在使用 react-test-renderer 的 Jest 快照测试中,Refs 为空 - Refs are null in Jest snapshot tests with react-test-renderer 使用 React-Test-Renderer 测试嵌套的 React 组件 - Testing of Nested React components using React-Test-Renderer 使用react-test-renderer进行快照测试 - snapshot testing with react-test-renderer "在 react-test-renderer 测试中渲染 jest 快照之前运行 useEffect 钩子" - Run useEffect hook before rendering jest snapshot in react-test-renderer test react-test-renderer不正确的对等依赖 - react-test-renderer incorrect peer dependency 使用 react-test-renderer 测试异步 componentDidMount() - Testing async componentDidMount() with react-test-renderer react-test-renderer浅渲染器在生产模式下不可用 - react-test-renderer shallow renderer is not available in production mode 如何使用@testing-library/react 和 react-test-renderer 测试由 Redux 状态控制的输入值? - how to test input value controlled by Redux state using @testing-library/react and react-test-renderer?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM