reactjs - 通过使用 Jest 在 Router 中将函数作为 props 传递来测试函数
问题描述
我是新来为反应中的功能组件编写测试用例。我有一个下面的功能组件,我需要为 checkCreated() 函数编写一个测试用例,它在其中调用一个 useState 函数。
function TestComponent() {
const [Icon, setIcon] = useState(false);
const checkCreated = status => {
setIcon(status);
};
<Router>
<Route exact path="/test" component={test} />
<Route exact path="/sample1" render={props => ( <Sample1 {...props} checkCreated ={ checkCreated } /> )} />
<Route exact path="/sample2" render={props => ( <Sample2 {...props} checkCreated ={ checkCreated } /> )} />
/>
</Router>
export default TestComponent;
有人可以帮助我编写测试用例来覆盖使用路由器的 checkCreated()。
解决方案
推荐阅读
- java - Mockito 在测试中没有从控制器模拟功能
- oracle - 选择更改交互式报告oracle apex时刷新表单
- python - sqrt 但用于卷积
- python - 如何使用 pycparser 删除 AST 节点?
- python - 如何将列表的类属性的值放入新列表中?
- python - json.decoder.JSONDecodeError PYTHON
- c++ - c++:通过花括号调用构造函数?
- python - 使用 multiprocessing.manager 的问题
- android - 使用改造的响应正文的字节大小是否有限制?
- javascript - 如何完全停止/重置/重新初始化 Matter.js canvas/world/engine/instance