如何在许多对象中声明2个键

时间:2020-01-22 16:34:14

标签: karate

响应=

[
  {
    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
    }
  }
]

曾经尝试解决这个问题,但是却找不到最佳的方法。

我正在尝试检查键fuelType = PETROL,然后键fuelCost必须等于1.1

响应中有许多对象,我想在每个对象中声明2个键(fuelType和Fuelcost)。

我尝试了以下操作:

Given path 'url'
    When method GET
    Then match each response[*] contains {[*].fuelType:PETROL , [*].tco.fuelCost:1.1}

请帮助 谢谢

1 个答案:

答案 0 :(得分:2)

尝试一下,如有需要,请进行调整:

formGroup.patchValue(value)