Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to write a test in Postman to check if there is no string value in an array?

I get back a body with an array of values.

[
     "test",
     "rootKeys",
     "HiveName",
     "hiveName",
     "Birthday",
     "main_hive"
]

I need to write a test that checks that the array has no values, like "TestCreate".
How can this be done?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

One possible solution is to use to.not.include().

pm.test("String 'TestCreate' not in array", () => {
    const parsedResponseBody = pm.response.json();
    pm.expect(parsedResponseBody).to.be.a("array");
    pm.expect(parsedResponseBody).to.not.include("TestCreate");
})
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading