使用data-test属性来测试组件是否在 Jest 测试用例中渲染而不会崩溃。但该属性也在 DOM 节点上呈现。有什么办法可以防止这种情况发生吗?
最佳答案
您可以使用这个包:
babel-plugin-react-remove-properties
并在你的 babelrc 中设置:
{
"env": {
"production": {
"plugins": [
["react-remove-properties", {"properties": ["data-test", "data-foo", /my-suffix-expression$/]}]
]
}
}
}
这将删除您在生产版本中列出的所有属性。
关于javascript - 防止特定属性在react js中的DOM节点上渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61257142/