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.