Reputation: 17
I am trying to figure out, why I can't seem to write a test like
pm.expect(responseBody.id).to.be.an("integer");
but apparently have to use "number". The test fails with the message:
AssertionError: expected 12345 to be an integer I am sure that it is an integer, though. I've also tried it with other responses.
When I test the response against a schema, where the id is of type "integer", it works.
So, do I only have the possibilty of checking for a "number" in the pm tests or does "number" in this case mean "integer"?
Unfortunately, I haven't found any helpful information on the postman website. Any help would be appreciated!
Upvotes: 1
Views: 4620
Reputation: 25921
You're not limited to using just the ChaiJS getters/data-types in the tests to check for an Integer.
I don't know what your response body looks like but I've mocked this test to show how you could use isInteger in the expect statement. This returns a true/false
so can be asserted against like this:
let test = { "number": 1234 };
pm.test("Check is an Int - 'With isInteger'", function () {
pm.expect(Number.isInteger(test.number), `Value: ${test.number} is a ${typeof test.number} and not a number`).to.be.true;
});
pm.test("Check is an Int - 'With a number'", function () {
pm.expect(test.number).to.be.a("number");
});
Upvotes: 5