Pinpoint a problem in data array in case of failure

Hello, guys! How I can solve this: In my test, I check the response body like this:

pm.test("Should have correct response body", function () {
    var expectedJson = JSON.parse(expectedBody);
    var keys = Object.keys(expectedJson);
    var jsonData = pm.response.json();
    keys.forEach(key => pm.expect(jsonData[key]).to.eql(expectedJson[key], "Wrong value for " + 
    key));
});   

But if I have a mismatch in value in the array I have a message where output only name of the array where was a mistake: Should have a correct response body

AssertionError: Wrong value for filterDataUi: expected { Object (locations, types, ...) } to deeply equal { Object (locations, types, ...) } , 

but I want to see here the name of key and value where was incorrect value.
For example :

AssertionError: Wrong value for batteries: expected '0.0 kWh' to deeply equal '0.1 kWh' . 

It doesn’t work with arrays

Hi @drunyak!

Could you clarify what your specific goal/query is?

What other solutions/workarounds have you tried thus far?

Hi, Sure. 1. I want to check response body. I mean to check key and value JSON response body. We often update our project and I wanna know if response body comes with a wrong value and I wanna know where the value was changed and for whom
2. I’ve tried with .xor() or _.differenceWithm (https://stackoverflow.com/q/38865869/11922633), but I don’t have enough experience (I’m a newbie)

Can you provide an example of what those 2 expected values are please?

It will be easier to run this locally with a mock of the response body and the expected body.

For example . I have expected body :

const expectedBody = {"filter":{"locations":["Easteighborhood","Northern","Southern"],"types":["Industrial"],"users":["Consumer1"],"met":["5000"],"select":["500"],"val_u":["Cons"],"ders":["storage","storage","value_x","value_y","storage"],"Type":""},"Map":{"Consum":[1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0]

If I got response body like this:

{"filter":{"locations":["Ea**changevalue**","Northern","Southern"].......... 

My test was failed and output:

Should have correct response body | AssertionError: Wrong value for filter: expected { Object (locations, types, ...) } to deeply equal { Object (locations, types, ...) } 

But I don’t know what the value and key are incorrect. (It will be hard to search an error for our devs)

I wanna see like this :

AssertionError: Wrong value for location: expected 'Easteighborhood' to deeply equal 'Ea**changevalue**'.

I mean this returns unhelpful output when comparing json objects. I compare two objects with the eql / deep.equal assertion, and they are not equal.
At the momen the return is something like:
AssertionError: expected { Object (...) } to deeply equal { Object (...) }

This return is not helpful at all, as there is no reporting on the differences.
I would expect something like this:

AssertionError: expected { Object (...) } to deeply equal { Object (...) } + diff like output of (for example) the stringified json representation.

That would make debugging so much easier! Is it possible to do?

These messages are coming from the Chai library that used to do the assertion.

From the test at the beginning of your thread it looks like you’re checking the keys - wouldn’t some form of schema validation be better in this situation?

That would give you the ability to check a number of different aspects of the response and also give you a list of items that don’t meet the criteria.

These two videos might help give an idea of how to perform this checks:

I spent on this 2 days . And as I know validation schema only validate struct JSON and types, not values… And we often have updates our project and if I wanna update all my tests I have to Ctrl+c / Ctrl+v for updates this. Not a good way. And can you give me example how I can implement(solve) (for your guides) my problem , if I don’t right