title: POSTman - Test with custom function throws an assertion error
body: <p>I am doing some test with Postman analysing JSON files. I realised that most of the time I end up making the same test over a bunch of properties, so I decided to make a custom function and add it to the test as a parameter.</p>
  
  <p>Once I do that, whenever an assertion fails it will throw an assertion error instead of failing the test itself. The test won't appear in the Tests Results window.</p>
  
  <p>It works when the assertion is successful though. The test passes and shows in the Test Results window.</p>
  
  <p>It works without a custom function, but in that case, every test will have its own function, with the same line of code, and that's what I wanted to avoid.</p>
  
  <pre><code>function myFunction(propertyName,testData) {
      {   
              return pm.expect(testData).to.have.property(propertyName);
      }
  }
  
  var data = JSON.parse(responseBody);
  
  var testData = data.entries;
  /*TESTS USING CUSTOM FUNCTION*/
  for (var i = 0; i &lt; 5; i++) { 
      try{
      //This test PASSES and shows in the Test Results window.
          pm.test("test1", myFunction('summonerId',testData[i])); 
      }catch(error){
          console.log(error);
      }
      try{
      //This test PRODUCES AN ERROR and DOESN'T shows in the Test Results window.
          pm.test("test2", myFunction('somethingElse',testData[i])); 
  
      }catch(error){
          console.log(error);
      }
   }
  /*TESTS USING ONE FUNCTION PER TEST*/
  for (var i = 0; i &lt; 5; i++) { 
  
      try{
      //This test PASSES and shows in the Test Results window.
          pm.test("test1", function(){
             pm.expect(testData).to.have.property('summonerId'); 
          }); 
  
      }catch(error){
          console.log(error);
      }
      try{
      //This test FAILS and shows in the Test Results window, without errors
          pm.test("test2", function(){
              pm.expect(testData).to.have.property('somethingElse'); 
          });
      }catch(error){
          console.log(error);
      }
   }
  </code></pre>
  
  <p>So when using a custom function, if an assertion is successfull everything is fine and the test is shown as PASSED, BUT if an assertion fails, it throws an error instead of failing the test, and the test is not shown as 'FAILED'.</p>
  
  <p>ASSERTION ERROR:</p>
  
  <pre><code>message: "expected { Object (summonerId, summonerName, ...) } to have property 'somethingElse'"
  name: "AssertionError"
  showDiff: false
  stack: "AssertionError: expected { Object (summonerId, summonerName, ...) } to have property 'somethingElse'
      at myFunction (eval at exec (evalmachine.&lt;anonymous&gt;:13040:2548), &lt;anonymous&gt;:9:52)
      at Object.eval (eval at exec (evalmachine.&lt;anonymous&gt;:13040:2548), &lt;anonymous&gt;:24:30)
      at Uniscope.exec (evalmachine.&lt;anonymous&gt;:13040:2583)
      at module.exports (evalmachine.&lt;anonymous&gt;:69:538)
      at Object.&lt;anonymous&gt; (evalmachine.&lt;anonymous&gt;:72:1871)
      at evalmachine.&lt;anonymous&gt;:16:26
      at Array.forEach (&lt;anonymous&gt;)
      at Object.emit (evalmachine.&lt;anonymous&gt;:15:54)
      at evalmachine.&lt;anonymous&gt;:52:24
      at evalmachine.&lt;anonymous&gt;:5:21"
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/5yqKD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5yqKD.png" alt="enter image description here"></a>
  Total test shows 15 test. 10 PASSED 5 FAILED.</p>
  
  <p>5 test are missing (Those that should FAIL, while using the custom function). </p>
  
  <pre><code>{
      "tier": "CHALLENGER",
      "leagueId": "65ebcd4f-368c-30f6-a635-976beb0e1a8c",
      "queue": "RANKED_SOLO_5x5",
      "name": "Varus's Outriders",
      "entries": [
          {
              "summonerId": "bPZhuLrFtF8ntu6a3JfnYNFX-NfG0LFX7aelPDd2Xegav-MM",
              "summonerName": "dang qiu qian",
              "leaguePoints": 739,
              "rank": "I",
              "wins": 162,
              "losses": 130,
              "veteran": true,
              "inactive": false,
              "freshBlood": false,
              "hotStreak": false
          },
          {
              "summonerId": "gk0lUIs1j9pMAWxa723hurPSDXAGbaXFJRdfek9WfQvWURA",
              "summonerName": "DV1 Matislaww",
              "leaguePoints": 795,
              "rank": "I",
              "wins": 757,
              "losses": 680,
              "veteran": false,
              "inactive": false,
              "freshBlood": false,
              "hotStreak": false
          }
  ]}
  </code></pre>