jestjs - “toHaveStyleRule”在 Jest(React Typescript)中不起作用,但是 toHaveStyle 可以
问题描述
我正在做一些测试并且 toHaveStyle 没有返回任何错误,但是当我在 toHaveStyleRule 中应用相同的语法时,它最终给了我以下错误:
No style rules found on passed Component
21 |
22 | // error
> 23 | expect(screen.getByTestId('icone')).toHaveStyleRule('width', '5rem')
但是测试是一样的!有人可以告诉我错误的原因吗?
测试:
// Ok
expect(screen.getByTestId('icone')).toHaveStyle({ width: '5rem' })
// Error
expect(screen.getByTestId('icone')).toHaveStyleRule('width', '5rem')
.Babelrc:
{
"presets": ["next/babel", "@babel/preset-typescript"],
"plugins": [
[
"babel-plugin-styled-components",
{
"ssr": true,
"displayName": true
}
]
],
"env": {
"test": {
"plugins": [
[
"babel-plugin-styled-components",
{
"ssr": false,
"displayName": false
}
]
]
}
}
}
解决方案
推荐阅读
- css - 在 Google 上隐藏已经访问过的结果?也许使用样式表?
- spring - 在 Spring 上实现 REST API 的两种方法
- javascript - Vuejs2 - 如何将两个数组中的元素与计算属性进行比较?
- javascript - `textNode.splitText(pos)` 在 Safari 中弄乱了插入符号的位置,将其移动到新节点之前。漏洞?
- c# - 如何去除 ASP.NET CORE 中多层的循环依赖
- c# - REST api 版本控制在技术上是如何实现的?
- java - 处理多个版本的 XSD 生成的类
- sql - 如何在oracle sql中的where条件中使用case语句?
- excel - 来自不同工作表的 Vlookup 动态范围参考
- telegram - 如何向 api.telegram.org 发送大消息