How can I check a string if it contains a specific string? (Beginning, middle, end)

How can I check a string if it contains a specific string? (Beginning, middle, end)

Currently, Iโ€™m using โ€œto.include()โ€ but it is checking the string value if it is exactly the string inside my to.include().
image

I am getting this error:

I want to create a verification on LIKE search feature i am working on.

One of possibility is to use match:

pm.test("Is a substring in string", () => {
    pm.expect(pm.response.json().key).to.match(/regex/);
});

And a tip from my side. To not waste time for awaiting answers, Iโ€™m searching for it (cuz itโ€™s certain, most of them already were answered). The key is to make a point questions (which is actually good practice in QA business, isnโ€™t it?).

It was less than 5 min to find:

  1. Google: chai how to assert substring of string
    Google answers
  2. First answer from top: Chai.js - Check if string contains substring from a list - Stack Overflow (since chai is inside Postman)

Good luck

1 Like