title: How to test throw new error JavaScript
body: <p>I'm trying to write unit-tests. In case the function gets the negative number it throws new error.</p>
  
  <pre><code>   Obj = function () { 
  }; 
  Obj.prototype.Count = function (number) { 
      if (number &lt; 0) { 
          throw new Error("There is no function for negative numbers"); 
      } else...
  </code></pre>
  
  <p>My unit-tet function:</p>
  
  <pre><code>function test(then,expected) {
          results.total++;
          var m1=new Obj();
          if (m1.Count(then)!=expected){
            results.bad++;
              alert(m1.Count(then)+" not equal "+expected);
          }
      }
      var results = {
          total: 0,
          bad: 0
      };
  </code></pre>
  
  <p>Then I'm trying to run the tests</p>
  
  <pre><code>test(5,120) 
  test(-5, "There is no function for negative numbers");
  </code></pre>
  
  <p>The first one works correctly, but I don't know what to write to 'expected' for negative numbers. The example doesn't work.
  Could you advise me, please?</p>
  
  <p>Thank you!</p>