Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

POSTMAN jetpacks TESTING within for loop

Hitting API w/ GET request, checking if item has been deleted by globals.id variable, have test inside forloop and when I run test returns 0/0 tests passed. All of my console logs within the for loop work, the objects contain values matching what I have as well. Anyone know how to do this?

var data = JSON.parse(responseBody);


for (var i = 0; i < data.length; i++){
  tests["id has been deleted"] = data[i].id !== globals.id;
  if(data[i].id !== globalID){
    tests["id has been deleted"] = data[i].id !== globals.id;
    return true;
  }
}
like image 264
Ranson Namba Avatar asked May 28 '15 01:05

Ranson Namba


1 Answers

I could make test with for loop. My Json:

{
  "rows": [
    {
      "id": "2804",
      "title": "Some title",
      ...
    },
    ...
  ],
  "total": "2788"
}

My test:

for (var i in data.rows){
    var obj = data.rows[i];
    tests["title of row #" + i + " is not null"] = !!obj.title;
    tests["title of row #" + i + " is not empty"] = obj.title !== "";
}

But if I use "return true" Postman shows "Tests (0/0)"

like image 105
Ruslan Mansurov Avatar answered Sep 29 '22 08:09

Ruslan Mansurov