使用 Chai/Mocha 检查 JSON 数组中的值
Check for value in a JSON array using Chai/Mocha
我有一个函数是 return 一个 JSON 数组
[
{
"coordinates": {
"lat": 1,
"lng": 2
},
"name": "33301 - Fort Lauderdale, Florida"
},
{
"coordinates": {
"lat": 3,
"lng": 4
},
"name": "33301 - Atlanta, Georgia"
}
]
如何编写 Chai expect 语句来检查名称值...
基本上,我想看看结果名称参数是否包含“33301 - 佐治亚州亚特兰大”
感谢您的帮助
您可以筛选出数据并验证:
//filter your data by name
const filteredData=myObject.filter(object=>object.name==='33301 - Atlanta, Georgia');
// now you can check the length of that filtered array
expect(filteredData).to.have.length(1);
我有一个函数是 return 一个 JSON 数组
[
{
"coordinates": {
"lat": 1,
"lng": 2
},
"name": "33301 - Fort Lauderdale, Florida"
},
{
"coordinates": {
"lat": 3,
"lng": 4
},
"name": "33301 - Atlanta, Georgia"
}
]
如何编写 Chai expect 语句来检查名称值...
基本上,我想看看结果名称参数是否包含“33301 - 佐治亚州亚特兰大”
感谢您的帮助
您可以筛选出数据并验证:
//filter your data by name
const filteredData=myObject.filter(object=>object.name==='33301 - Atlanta, Georgia');
// now you can check the length of that filtered array
expect(filteredData).to.have.length(1);