Search code examples
jsoninsomnia

Insomnia - Assert object where key is empty value


I'm using Insomnia to test an API, and in one of the responses, the key has an empty name. Is there a way to validate the value of that key?

{
  "QueryId": "queryid_1",
  "Succeeded": false,
  "Errors": {
    "": [
      "The VehicleKey field is required."
    ]
  },
  "Extras": null
}

I've tried:

expect(body.Errors.''[0]).to.equal("The VehicleKey field is required.") 
expect(body.Errors.""[0]).to.equal("The VehicleKey field is required.")  
expect(body.Errors.key[0]).to.equal("The VehicleKey field is required.")  

but nothing works.


Solution

  • Since in Insomnia you write your expectations in JavaScript, therefore the question here is really how to reach a value in a JavaScript object where the key is an empty string:

    expect(body.Errors[''][0]).to.equal('The VehicleKey field is required.');