Postman response is as below: '''{ "error" : "validation error at #/test/TC_1594792360026/test" }'''
I would like to verify this error message string. Digits are changed every time so I want to use it regex for that. I think regex [0-9]+ should work. But I don't know how to frame it in Postman.
I am using it in postman as below: str t = "validation error at #/test/[0-9]+/test";
pm.expect(t).match(jsonData.error)
and Postman throws an error as "TypeError: e.exec is not a function"
Postman response is as below: '''{ "error" : "validation error at #/test/TC_1594792360026/test" }'''
I would like to verify this error message string. Digits are changed every time so I want to use it regex for that. I think regex [0-9]+ should work. But I don't know how to frame it in Postman.
I am using it in postman as below: str t = "validation error at #/test/[0-9]+/test";
pm.expect(t).match(jsonData.error)
and Postman throws an error as "TypeError: e.exec is not a function"
Share Improve this question asked Jul 15, 2020 at 6:10 Pratik PatelPratik Patel 1131 gold badge2 silver badges8 bronze badges 1 |2 Answers
Reset to default 17The correct syntax to use regex in the assertion would be:
pm.expect(jsonData.error).to.match(/validation error at #\/test\/TC_[0-9]+\/test/)
Each assertion getter need to start with .to
and you need to have a valid regex string inside the .match()
method.
var currentDate = new Date();
var year = currentDate.getFullYear() - age;
var month = Math.floor(Math.random() * 12) + 1; // Random month (1-12)
var day = Math.floor(Math.random() * 28) + 1; // Random day (1-28)
// Ensure a valid date (e.g., avoid February 30th)
var maxDay = new Date(year, month, 0).getDate();
if (day > maxDay) {
day = maxDay;
}
var dob = new Date(year, month - 1, day); // Subtract 1 from month because it's 0-indexed
return dob.toISOString().slice(0, 10); // Format as YYYY-MM-DD
// Specify the desired age var desiredAge = 30;
exec
? – Bren Commented Jul 15, 2020 at 6:44