如果我有一个对象数组的对象
{ "places": [ {city: "Pittsburgh", state: "PA"} ] }
如何测试以查看索引0(places [0])处的数组是否具有带键的对象" city"?我尝试了这个,但它没有工作
expect( {"places": [ {"city": "Pittsburgh", "state": "PA"} ] } ).to.nested.include({"places[0]" : "city"});
答案 0 :(得分:3)
您应该使用to.have.nested.property
代替to.nested.include
:
var obj = {"places": [ {"city": "Pittsburgh", "state": "PA"} ] };
expect(obj).to.have.nested.property("places[0].city");