How to test results returned in plain text

I am trying to test results returned in plain text (rather than in JSON). When I submit a request (with missing data) to our API I get a response in plain Text

example of response : {“Result”:false,“Message”:["‘forename’ must not be empty."]}

My test is this:
pm.test(“Response should contain Result equals ‘false’”, function () {
let jsonRespData = pm.response.json();

pm.expect(jsonRespData).to.have.property(‘Result’, false);
pm.expect(data.Message).to.equal("‘forename’ must not be empty.");
});

The section of the test to check the message always fails with the fail message:
Response should contain Result equals ‘false’ | AssertionError: expected undefined to equal ‘‘Title’ must not be empty.’

and I can’t work out how to get it to pass.
Any help will be appreciated.

Hey @adam.allford1701

Welcome to the community! :trophy:

Would something like these assertions work for you?

pm.expect(jsonRespData.Result).to.be.false

And

pm.expect(jsonRespData.Message[0]).to.equal("‘forename’ must not be empty.");

Hi dannydainton,

Thanks for your email and your suggestion which has worked.

Thanks for you help.

1 Like