Karate 无法使用没有标识符名称的数组断言单个数组中的所有元素
答复:Karate 无法使用没有标识符名称的数组断言单个数组中的所有元素,karate,Karate,答复: [ { id: "1", modelId: "301", modelName: "x", trimId: "301", trimName: "up!", derivativeName: "xx", fuelType: "PETROL", tco: { price: { tco: null, retail: 12, offer: null, sub
[
{
id: "1",
modelId: "301",
modelName: "x",
trimId: "301",
trimName: "up!",
derivativeName: "xx",
fuelType: "PETROL",
tco: {
price: {
tco: null,
retail: 12,
offer: null,
subsidy: null,
residual: null
},
milesPerYear: 10000,
mpg: 51.5,
fuelCost: 1.1,
milesPerKW: 0,
monthsOfOwnership: 48,
energyCost: 12,
tax: 42,
comparable: false
}
},
{
id: "1239",
modelId: "301",
modelName: "up!",
trimId: "301",
trimName: "x",
derivativeName: "xx",
fuelType: "PETROL",
tco: {
price: {
tco: null,
retail: 1,
offer: null,
subsidy: null,
residual: null
},
milesPerYear: 10000,
mpg: 53.2,
fuelCost: 1.1,
milesPerKW: 0,
monthsOfOwnership: 48,
energyCost: 12,
tax: 4,
comparable: false
}
}
]
我试图检查钥匙燃油类型
=汽油时,钥匙燃油成本
必须等于1.1
我试过以下方法
* def isValid = function(x) { return response[0].fuelType == "PETROL" && response[0].tco.fuelCost == 1.1}
* match each response === '#? isValid(_)'
^^但这只是断言顶层元素
我尝试了以下方法:
* def isValid = function(x) { return response[*].fuelType == "PETROL" && response[*].tco.fuelCost == 1.1} * match each response === '#? isValid(_)'
* match each response === '#? isValid(_)'
^^但这会抛出一个操作数错误
在一个没有标识符名称的数组中,我有大约260个元素,我需要在所有260个元素中为``fuelType==“Petrole”&fuelCost==1.1断言这两行非常有效:
* def isValid = function(x) { return x.fuelType == "PETROL" && x.tco.fuelCost == 1.1 }
* match each response == '#? isValid(_)'
你用了一个三重等式,这是错误的。阅读文档:我尽量简短,但显然不起作用。我补充了另一个,谢谢,太好了,一个“简单的例子”的全部要点都没有了。不管怎样,看看我的答案