问题标签 [react-test-renderer]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
javascript - react-native-vector-icons + mocha: Invariant Violation
This is my Component. It runs without problems on emulator/phone:
But when I run the unit test in this file (mocha --recursive test/**/*.js):
It throws:
Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in, or you might have mixed up defau lt and named imports.
Check the render method of
MyComponent
.
It works if I use a <View>
instead of the <Icon>
but it should be mocked.
How can I fix this?
react-native - 如何使用 react-test-renderer 和 jest 测试包含嵌套组件的反应组件,这些组件是连接组件?
实际上,我正在使用 react-test-render 和 jest 在 react-native 中编写测试用例?我有一个需要测试的组件,该组件包含嵌套组件,它们是连接组件。以下是我为测试组件而编写的代码:
但它告诉我一个错误说:
不变违规:在“Connect(SocialServiceProfileImage)”的上下文或道具中找不到“商店”。要么将根组件包装在 a 中,要么将“store”作为道具显式传递给“Connect(SocialServiceProfileImage)”。
我知道我可以使用“react-test-renderer/shallow”进行浅渲染,但它不允许我像 Enzyme 那样从 DOM 中找到任何节点。谁能帮我这个?。我没有酶,也不想用于 react-redux-mock-store。
reactjs - React 测试库:我是否需要为每个测试键使用新的选择器进行新的测试?
我正在使用 React 测试库构建一个带有 TDD 的 React 应用程序。
TLDR:选择器(例如toBeInTheDocument()
)似乎只在render
. 那正确吗?
我使用 CRA 制作了应用程序,这是我的src/setupTests.js
:
以下是我写的测试:
这是我写的组件:
describe
现在,如果我运行这些测试,每个块只有前两个通过。
例如,如果我给出任何it
测试 a.only
它通过。
到底是怎么回事?我不能为多个断言重用相同的测试设置吗?我必须render
为每个人打电话it
吗?
reactjs - 如何测试依赖于 useContext 钩子的反应组件?
我有一个使用的组件,useContext
然后它的输出取决于上下文中的值。一个简单的例子:
使用 react 和 jest 快照中的浅渲染器测试此组件时。如何更改 的值NameContext
?
reactjs - 浅层测试错误 - 方法“props”应在 1 个节点上运行。找到了 0 个
我正在做浅层测试。这是我的容器组件代码:
jcpenney1.test.js页面:
所以在这里我只是检查 Formbody 子组件是否由属性 parentId 组成。当我运行测试时,我收到以下错误:
有关详细信息错误,请单击此链接:
请帮助我如何解决这个问题
reactjs - 使用 Jest 和 React-test-renderer 测试伪类
我在 css 中有一些悬停伪类,并且想要运行测试并检查它们是否正常运行。Jest 可以做到这一点吗?抱歉,我在这里缺乏知识,我只是使用 Jest 的一天。
CSS:
reactjs - 测试使用 Hooks 获取数据的 React 组件
我的 React 应用程序有一个组件,它从远程服务器获取要显示的数据。在前钩子时代,componentDidMount()
是去的地方。但现在我想为此使用钩子。
我使用 Jest 和 Enzyme 的测试如下所示:
测试成功,但它记录了一些警告:
App 组件的唯一更新发生在 Promise 回调中。我怎样才能确保这发生在块内act
?文档明确建议在块之外进行断言。act
此外,将它们放入内部不会改变警告。
react-native - 升级到 react-native 0.58 后,Jest 测试中断
升级到 react-native 0.58.6 后我的所有测试都使用react-test-renderer
或中断enzyme
我得到的错误是例如
TypeError: Cannot read property 'default' of undefined
Expected value to be truthy, instead received undefined
TypeError: Cannot read property 'dive' of undefined
TypeError: Cannot read property 'find' of undefined
有人经历过类似的行为吗?我尝试了不同版本的酶,或者开玩笑,但没有运气。
我的依赖:
复制者
react-native - 使用 react-router-native 的链接进行测试时出现“TypeError:无法读取未定义的属性‘默认’”
对于使用 react-router、jest 和 react-test-renderer 的 react-native 应用程序,该<Link>
组件似乎不可测试。react-router 文档没有提到必须为 react-native 做任何特别的事情(模拟?),我的测试只有在 react-router 的组件包含在正在渲染的树中时才会爆炸<Link>
。其他组件(例如<Text>
, <Router>
)没有这个问题。
这个基本的 react-native 项目重现了爆炸测试。否则,该应用程序会在手机内部按预期构建和运行。
我有配置问题吗?它是无证的,还是我只是忽略了它?还是我应该放弃并改用酶?那会有帮助吗?
这是显着的测试输出:
reactjs - TypeError:无法读取未定义的属性“baseVal”
我正在使用 react-test-renderer 的渲染器对我的反应组件进行单元测试。它工作正常,但在使用 ReactCssTransitionGroup 后,我收到以下错误“TypeError:无法读取未定义的属性 'baseVal'”。不知道如何解决这个问题
我验证了这个问题是由 ReactCssTransitionGroup 引起的
下面是我的组件文件:
下面是我的单元测试文件