1

I have a body response on Postman that return this for me:

[
{
    "key": "Dateline Standard Time",
    "value": "(UTC-12:00) International Date Line West"
},
{
    "key": "UTC-11",
    "value": "(UTC-11:00) Coordinated Universal Time-11"
},
{
    "key": "Aleutian Standard Time",
    "value": "(UTC-10:00) Aleutian Islands"
}]

So, inside the Tests tab, what should I write to test if the response is EXACTLY that in the same order?

I tried something like this:

    pm.test("Body is correct", function(){
      pm.response.to.have.body("
     [
    {
        "key": "Dateline Standard Time",
        "value": "(UTC-12:00) International Date Line West"
    },
    {
        "key": "UTC-11",
        "value": "(UTC-11:00) Coordinated Universal Time-11"
    },
    {
        "key": "Aleutian Standard Time",
        "value": "(UTC-10:00) Aleutian Islands"
    }]
    ");

But still not working.

Thx!

1 Answers1

2
pm.test("Body is correct", function () {
    pm.expect(pm.response.json()).to.deep.equal(
        [
            {
                "key": "Dateline Standard Time",
                "value": "(UTC-12:00) International Date Line West"
            },
            {
                "key": "UTC-11",
                "value": "(UTC-11:00) Coordinated Universal Time-11"
            },
            {
                "key": "Aleutian Standard Time",
                "value": "(UTC-10:00) Aleutian Islands"
            }]
    )
});

use deep equal

PDHide
  • 18,113
  • 2
  • 31
  • 46