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?