简体   繁体   English

如何使用 React 测试库为返回 Jest 中的组件的 Switch 语句编写单元测试用例

[英]How to write Unit Test case for Switch Statement that returns Component in Jest with React Testing Library

When I writing test case, I was able to reach out to case 0, but not able to reach other 1当我编写测试用例时,我能够接触到案例 0,但无法接触到其他案例 1

 const tabContent = (isCurrent) => { switch (isCurrent) { case 0: return <Component 1 />; case 1: return <Component 2 />; default: return null; } };

Then set isCurrent to 1 to go to the first case tabContent(1) Any other value wil go to the default然后将 isCurrent 设置为 1 将 go 设置为第一种情况 tabContent(1) 任何其他值将 go 设置为默认值

暂无
暂无

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

相关问题 如何使用 React、Jest 和 React-testing-library 为带有令牌的 api 调用编写单元测试? - How can I write unit test for api call with token using React, Jest and React-testing-library? 如何使用 jest 和 react 测试库为返回 function 的嵌套 jsx 编写测试用例 - how to write test case for nested jsx returning function using jest and react testing library 如何使用 onClick 函数 Jest/React 测试库测试 React 组件 - How to test react component with onClick function Jest/React testing library React 测试库 + Jest:如何测试接收数字然后对其进行格式化的组件 - React testing library + Jest: How to test a component that receives a number then format it 如何使用Jest和Enzyme为简单的React组件编写测试用例 - How to write a test case for a simple React component using Jest and Enzyme 测试开关箱-单元测试 - Test Switch Case - Unit testing 如何使用 Jest 和 React 测试库测试 className - How to test a className with the Jest and React testing library 带有三元运算符的 Jest 单元测试开关案例 - Jest unit test switch case with ternary operator 如何为 componentDidMount() 编写单元测试用例并导出默认 connect(null, updateProps)(<componentname> ) 在 React 中使用 JEST/酶?</componentname> - How to write unit test case for componentDidMount() and export default connect(null, updateProps)(<ComponentName>) with JEST/Enzyme in React? 如何为 React useEffect 中的代码编写 Jest-enzyme 测试用例,其依赖项在其子组件中更新 - How to write a Jest-enzyme test case for code in React useEffect whose dependencies are updated in its child component
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM