I have tried with !== null
, but it is returning PASS even when the field is returning 0
or empty string.
Empty response — JSONError: No data, empty input at 1:1test("Status code is 204", () => { pm. response.to.have. status(204);}); You can also check that the response is indeed empty (if this is the expected behaviour).
#1) Firstly, we try to store the schema for the JSON in a local variable. #2) We now store JSON from the actual request execution through pm object. #3) Now, we add an assertion in pm. expect() block, and use the TinyValidator library to validate JSON response against the given schema.
In Postman, we can write the assertion in many ways. One of the simplest ways is the snippets, which are nothing but a block of codes that have some unique functions inside it and are available in the postman app. Users can easily access the snippets and can get the code inside the tests editor and run the test.
This works as of Mar-2019:
pm.test("To Check if Value is Null", function() {
var jsonData = pm.response.json();
pm.expect(jsonData.<yourfield>).not.eq(undefined);
)};
Did you try
pm.expect(response.your_field).to.eql(null);
?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With