【发布时间】:2019-11-22 03:53:12
【问题描述】:
我不是 JS 节点,并且在使用我的测试夹具(.json 文件)时遇到问题。这是我的 .json 文件:
{
"info": [
{
"type": "person",
"gender": "Male",
"altUrl": "http://www.testUrl.com",
"contact": {
"email": {
"type": "Work",
"address": "testEmail@email.com",
},
"phone": {
"type": "Mobile",
"number": "8989898989"
}
}
}
]}
在我的 .js 文件中,我有:
var account = require('../../myfile.json');
问题是,当我尝试访问 .json 文件中的数据时,它总是以未定义的形式返回。我调用 .json 文件的一个例子是:console.log(account.info.gender);
有没有人知道为什么我会得到未定义的值?任何帮助将不胜感激!谢谢
【问题讨论】:
-
account.info[0].gender?
标签: javascript node.js json unit-testing testing