Postman: How to check whether the field is returni

2020-02-26 08:07发布

I have tried with "!== null", but it is returning PASS even when the field is returning 0 or "".

10条回答
看我几分像从前
2楼-- · 2020-02-26 08:47

I have done similar, this is one part of the code and its works well Check this code

var jsonData = JSON.parse(responseBody);

for(i=0; i<jsonData.data.length; i++){
tests["due date is between given date range"] = jsonData.data[i].duedate < environment.Cenddate && jsonData.data[i].duedate > environment.Cstartdate;

tests["response body has department name"] = jsonData.data[i].department.name !== null;

}
查看更多
ゆ 、 Hurt°
3楼-- · 2020-02-26 08:52

I faced similar issue. But checking it in following way worked for me

tests["Item is not null"] = 
    jsonData.item !== undefined;
查看更多
男人必须洒脱
4楼-- · 2020-02-26 08:53

Did you try

pm.expect(response.your_field).to.eql(null);

?

查看更多
该账号已被封号
5楼-- · 2020-02-26 08:59

You can access response json like :

    var json = JSON.parse(responseBody);
    var yourVAr = json.yourVar
    if(yourVar == null){
        //your var is null here
    }
查看更多
登录 后发表回答