We are developing APIās and I need the ability to verify the entire payload of certain response bodies with exception of a dynamic āgenerateDateTimeā: ā2020-03-09T16:24:50.58ā, value. Iām using lodash test snippet below which works perfectly for static response bodies that have no dynamic valuesā¦ But I need a solution for either verifying the static response body + the dynamic āgenerateDateTimeā: or to somehow exclude the āgenerateDateTimeā: value in the test assertion.
var jsonData = JSON.parse(responseBody);
var _ = require(ālodashā);
tests[āCorrect Response Body is Returnedā] = _.isEqual(jsonData,
I just wanted to point out that the more modern way of writing tests in Postman is using the Chai.js assertion library. All code snippets support that now.
Since jsonData is a JavaScript object, I would simply remove the property generateDateTime from the response.
Thank you for the reply! Just for clarification your saying that I should be using the Chai assertions as opposed to lodash? I apologize Iām a bit of a newbie to Postman can you be specific about how and where to use the delete jsonData.generateDateTime; within the lodash test assertion I provided?
I agree with @vdespa here, for me Lodash isnāt needed and the newer pm.test function makes things more readable, in my opinion.
Also, for most Lodash functions like isEqual you donāt need to use a require statement to bring them into the sandbox environment. So if you removed the var _ = require(ālodashā); from your code, it would still work.