title: Jasmine - How to test errors?
body: <p><strong>THE SITUATION:</strong></p>
  
  <p>Hello guys. I am learning jasmine to test my angular app.</p>
  
  <p>I have create a basic function that does multiply two numbers.
  If the parameters given are not a number, the function throw an error.</p>
  
  <p>I then made two very basic tests.</p>
  
  <p>The first to check if the function properly multiply the numbers.
  The second to check if the function properly throw an error if a string is given as parameter.</p>
  
  <p>The first test pass, the second not. And i don't understand why.</p>
  
  <p><strong>THE CODE:</strong></p>
  
  <p><strong>The function:</strong></p>
  
  <pre><code>function Multiply( num1, num2 )
  {
  
      var result;
  
      if (isNaN(num1) || isNaN(num2)) 
      {
          throw new Error("not a number");
      }
      else
      {
          result = num1 * num2;
  
          return result;
      }
  
  }
  </code></pre>
  
  <p><strong>The spec:</strong></p>
  
  <pre><code>describe('The function', function () 
  {
      it('properly multiply two numbers', function () 
      {
          result = Multiply(10, 5);
          expect(result).toEqual(50);
      });
  
      it('throw an error if a parameter is not a number', function () 
      {
          result = Multiply(10, 'aaaa');
  
          expect(result).toThrow(new Error("not a number"));
  
      });
  
  });
  </code></pre>
  
  <p><strong>THE OUTPUT:</strong></p>
  
  <pre><code>2 specs, 1 failure
  Spec List | Failures
  The function throw an error if a parameter is not a number
  Error: not a number
  Error: not a number
      at Multiply (http://localhost/jasmine_test/src/app.js:8:9)
  </code></pre>
  
  <p>If i understand properly Jasmine. Both test should pass, because in the second case the function throw the error as we expected.</p>
  
  <p><strong>THE QUESTION:</strong></p>
  
  <p>How can i test if a function properly throw an error?</p>
  
  <p><br><br>
  <strong>EDIT:</strong></p>
  
  <p>I am trying this new code, but is still not working:</p>
  
  <pre><code>describe('The function', function () 
  {
  
      it('throw an error if a parameter is not a number', function () 
      {
  
          expect(function() { Multiply(10, 'aaaa') }).toThrowError(new Error("not a number"));
  
      });
  
  });
  </code></pre>
  
  <p><strong>OUTPUT:</strong></p>
  
  <pre><code>2 specs, 1 failure
  Spec List | Failures
  The function throw an error if a parameter is not a number
  Error: Expected is not an Error, string, or RegExp.
  </code></pre>