Do pm.test() and/or pm.expect() return anything

Do pm.test() and/or pm.expect() return anything?

What would the variable result in the code fragment below contain if anything?
var result = pm.test(“Some test”…)

It returns pm object itself - making it chainable.

So you can do:

pm
  .test(…)
  .test(…);
1 Like

Ok so the reason I ask is that I’ve got code similar to the following in a number of my tests.

pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);
});

if (pm.response.code === 200) {
var jsonData = pm.response.json();

pm.test("Has a Campuses aggregate", function () {
    pm.expect(jsonData).to.have.property('Campuses');
});

var campusesArray = jsonData.Campuses;
if (campusesArray === undefined || campusesArray === null) {
    return;
    }
    ...
}	

Which I’d like to change to something like the following

pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);
});

if (pm.response.code === 200) {
var jsonData = pm.response.json();

var result = pm.test("Has a Campuses aggregate", function () {
    pm.expect(jsonData).to.have.property('Campuses');
});

if (result.???? === ????) {
    return;
    }
    ....
}

In other words if the Campuses aggregate doesn’t exist then I’d like to exit at that point. The main driver for the checks in the code is that the request fails completely if I try to use the non-existent Campuses object to access any of it’s fields for further tests.

So what would I need to substitute for the ??? if what I want to do is at all possible?

I have done what you need like that

pm.test(“response is valid and have a body”, function ()
{
pm.response.to.be.ok;
pm.response.to.be.withBody;
pm.response.to.be.json;
pm.response.code === 200
pm.expect(pm.response.text()).to.include(“pss_external_id”);
}).test(“check others param”, function()
{
var response = JSON.parse(responseBody);
for (var i = 0; i <= 3; i++)
{
tests[response[i].pss_external_id + " est créé "] = response[i].pss_external_id.substr(b2b.length, 8) === “-PSS-NR-”;
}
});

Hi there,
Dig up the topic to check if some answer was found for that ?
Anything related to “pm.test” outcome is real pain. No boolean, unknown objects, no doc…
Thanks.