Arsenii
Arsenii

Reputation: 109

OR operator in Postman Response Tests

I have the following assertion in my postman script test, but for some reason the tests are failing when one of the following is missing: Lease, Finance, or cash in my response body. Is the "||" not the OR operator?

tests["Deal Type"] = responseBody.has("Lease" || "Finance" || "Cash");

Upvotes: 8

Views: 18078

Answers (3)

Surbhi Singh
Surbhi Singh

Reputation: 61

Write it is like this..

pm.expect(pm.response.data[0].DealType).to.be.oneOf(['Lease', 'Finance','Cash']);

Upvotes: 6

idefixcert
idefixcert

Reputation: 312

It should be something like:

pm.expect(pm.response.code).to.be.oneOf([201,202]);

Upvotes: 13

Paaz
Paaz

Reputation: 133

According to the postman docs the correct syntax would be

tests["Deal Type"] = responseBody.has("Lease") || responseBody.has("Finance") || responseBody.has("Cash");

Upvotes: 6

Related Questions