title: How to use conditional statement with Postman's new pm.* API?
body: <p>I have a question about how to use the new pm.* API with conditional statements. Please take a look at the following example code</p>
  <pre class="lang-js prettyprint-override"><code>if(pm.test(&quot;Status code is 200&quot;, function({
     pm.expect(pm.response.code).to.equal(300);})){
      
     var token = pm.response.headers.get(&quot;Authorization&quot;);
     pm.environment.set(&quot;JWT Token&quot;, token.substr(7));
      
     pm.test(&quot;Response body is empty &quot;, function () {
        pm.expect(pm.response.text().length).to.equal(0);
     });
  }
  
  console.log(pm.test(&quot;Status code is 200&quot;, function() {pm.expect(pm.response.code).to.equal(300)}));
  </code></pre>
  <p>As I may want to perform certain tests e.g. only when 200 is returned I wanted to use if. However, when I deliberately changed the equal value to 300 just to check if this works, both tests are run and the variable is set, even though the first test fails.</p>
  <p>The console.log returns an empty object instead of true/false for the assertion. And if I use something like</p>
  <pre class="lang-js prettyprint-override"><code>console.log(pm.expect(pm.response.code).to.equal(300));
  </code></pre>
  <p>I'll get an error message:</p>
  <blockquote>
  <p>There was an error in evaluating the test script:  AssertionError: expected 200 to equal 300</p>
  </blockquote>
  <p>Does anyone know how to solve this?</p>
  <p>Cheers</p>