Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

193
Views
Using IF/ELSE in Postman Test scripts

I am using Postman in order to test, But I am stuck on using if/else in the scripts.

My goal is to test if a property is visible in the response body. if the property is not there, I want postman to expect it be empty. and move on to the next test. The properties are nested in an array.

This is what I came up with so far.:

//Test of correct sub properties rijbewijs zijn meegestuurd
pm.test("Test if correct sub properties rijbewijs are sent", () => {
    if (pm.expect(matchesVacatures.rijbewijs).to.be.empty);
    else { pm.expect(matchesRijbewijs).to.have.property('codeSoortRijbewijs');}  
});

However, the test always "fails" if the array is not empty. How do I go about this, it might be something small that have I placed incorrectly in the test, but I cant quite figure it out.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Figured it out:

pm.test("Test if correct sub properties rijbewijs are sent", () => {
    if ((matchesVacatures.rijbewijs).length !== 0)
    {pm.expect(matchesVacatures.rijbewijs[0]).to.have.property('codeSoortRijbewijs');}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!