【问题标题】:TypeError: Cannot read property 'name' of undefined - react testingTypeError:无法读取未定义的属性“名称” - 反应测试
【发布时间】:2019-07-12 11:01:14
【问题描述】:

每当我运行测试时,我都会收到此错误。我正在使用 react-testing-library。

failed test

这是我要测试的代码和页面: api call and map

我的测试:enter image description here

老实说,我不确定为什么它在那里失败,页面呈现正常但测试不会通过,上面的屏幕截图信息量不是很大?如果不够详细,请道歉?有什么想法吗?

【问题讨论】:

  • 请以纯文本形式提供代码,而不是屏幕截图

标签: reactjs testing react-testing-library


【解决方案1】:

问题是data[index].fieldundefined。您的测试正在尝试访问 undefined 上的属性 name,这是一个 TypeError

我看到 data 来自 getKnowledgePageCategories 您在测试中嘲笑它。我建议记录您在模拟中返回的值,很可能是错误。

【讨论】:

    猜你喜欢
    • 2019-12-22
    • 1970-01-01
    • 2017-06-18
    • 2021-11-13
    • 2022-01-14
    • 2022-06-22
    • 2015-10-16
    • 2021-12-28
    • 2021-08-16
    相关资源
    最近更新 更多