【问题标题】:ReferenceError: type is not defined [closed]ReferenceError:类型未定义[关闭]
【发布时间】:2020-12-27 12:41:16
【问题描述】:

我在测试时遇到这个错误,ReferenceError: type is not defined如何解决?? 但是这里没有名为“type”的变量。

jestExpect(sample.datasource-type).toEqual('metadata');

【问题讨论】:

  • 请更新您的问题以包含Minimal, Complete, and Reproducible 代码示例、清除错误消息详细信息以及堆栈跟踪、调试信息等...
  • 现在检查。我已经更新了问题
  • 不确定是谁关闭了它,但它很容易重现,而且不是错字,但正如我所说,点符号在 JS 中对于 JS 对象的任意属性如何工作的一个怪癖。跨度>

标签: reactjs unit-testing jestjs react-fullstack


【解决方案1】:

Javascript 不接受标识符中的连字符。您需要将sample.datasource-type 替换为sample["datasource-type"]

【讨论】:

  • 是的,它解决了这个问题。感谢您的帮助
  • 你能接受这个答案吗?
猜你喜欢
  • 1970-01-01
  • 2019-01-14
  • 2014-08-04
  • 1970-01-01
  • 2021-11-08
  • 1970-01-01
  • 1970-01-01
  • 2013-12-27
  • 1970-01-01
相关资源
最近更新 更多