Search code examples
postmanpostman-collection-runner

Postman test case insetitive


I have a test case in the Postman which looks like:

pm.test("Last Name contains Bob", () => {
    const responseJson = pm.response.json();
    pm.response.to.have.status(200);
    pm.response.json().result.length >= 1;
    pm.expect(responseJson.result[0].last_name).to.include.a("Bob");
});

but that fail for a result which has BOBBY as last_name

I thought that by adding a to the assertion it will became case insensitive.

So what I'm doing wrong?


Solution

  • Solution for my case wast to use match with Regex

    pm.test("Last Name contains Bob", () => {
        const responseJson = pm.response.json();
        pm.response.to.have.status(200);
        pm.response.json().result.length >= 1;
        pm.expect(responseJson.result[0].last_name).to.match(\Bob\gmi);
    });