Search code examples
postmanpostman-newman

How to form pm.test assertions in Postman


Given the following transaction reply how would I form a pm.test assertion for it?

{
    "data": {
        "clearEmployerClaim": true
    }
}

This isn't working for me:

pm.test("clear employer claim status returned", () => { 
    const response = pm.response.json(); 
    pm.expect(response.clearEmployerClaim).to.be.true;
});

I would normally do it like this but I'm getting type errors when running this via Jenkins/Newman. It works fine run via Postman.

tests["C536773447 clear employer claim status returned"] = body.data.clearEmployerClaim === true;

Any help is appreciated.


Solution

  • You missed one level here.

    pm.expect(response.clearEmployerClaim).to.be.true; --> pm.expect(response.data.clearEmployerClaim).to.be.true;