Sulteric
Sulteric

Reputation: 527

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.

Upvotes: -1

Views: 93

Answers (1)

lucas-nguyen-17
lucas-nguyen-17

Reputation: 5917

You missed one level here.

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

Upvotes: 1

Related Questions