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

Time:09-21

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?

CodePudding user response:

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");
})

CodePudding user response:

I found a solution

pm.test("Hive Exists", function(){
         pm.expect(res.json()).to.contain.oneOf(['NewNameHive']);
     })
     pm.test('Not Exists', () => {
         pm.expect(res.json()).to.not.contain.oneOf(['newHive'])
     })
});

If anyone has options to improve this I would appreciate it

  • Related