您如何测试没有回报的语句反应开玩笑酶

发布于 2025-01-21 13:44:44 字数 373 浏览 1 评论 0原文

我正在学习开玩笑,酶,我只是无法弄清楚一些如此简单的东西。我的问题是,这种情况在另一个功能中。我需要检查状态OBJ是否不是null,然后分配一些变量并进行测试。当我检查代码覆盖范围时,它表明未涵盖IF语句。谢谢

async handleButton() {

if (this.state.obj !== null) {
   var employee = this.state.obj.employee.name;
   var employeeId = this.state.obj.employee.id;
 }
await this.setState({
   updateObj: {...someOldObj, employee, employeeId};
 });
}

I am learning jest, enzyme and i just cant figure out something so simple. My problem is that this condition is inside of another function. I need to check if the state obj is not null then assign some variables and test it. When I check code coverage it shows that the if statement is not covered. thanks

async handleButton() {

if (this.state.obj !== null) {
   var employee = this.state.obj.employee.name;
   var employeeId = this.state.obj.employee.id;
 }
await this.setState({
   updateObj: {...someOldObj, employee, employeeId};
 });
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文