title: Chai - expect function to throw error
body: <p>I'm quite new to Chai so I'm still getting to grips with things.</p>
  
  <p>I have written function that will check an API response and return either the correct messaging or throw an error. </p>
  
  <pre><code>networkDataHelper.prototype.formatPostcodeStatus = function(postcodeStatus) {
  
  if (postcodeStatus.hasOwnProperty("errorCode")) {
      //errorCode should always be "INVALID_POSTCODE"
      throw Error(postcodeStatus.errorCode);
  }
  
  if (postcodeStatus.hasOwnProperty("lori")) {
      return "There appears to be a problem in your area. " + postcodeStatus.lori.message;
  }
  
  else if (postcodeStatus.maintenance !== null) {
      return postcodeStatus.maintenance.bodytext;
  }
  
  else {
      return "There are currently no outages in your area.";
  }
  };
  </code></pre>
  
  <p>I've managed to write tests for the messaging, however, I'm struggling with the error test. Here's what I've written to date:</p>
  
  <pre><code>var networkDataHelper = require('../network_data_helper.js');
  
  describe('networkDataHelper', function() {
  var subject = new networkDataHelper();
  var postcode;
  
      describe('#formatPostcodeStatus', function() {
          var status = {
              "locationValue":"SL66DY",
              "error":false,
              "maintenance":null,
          };
  
          context('a request with an incorrect postcode', function() {
              it('throws an error', function() {
                  status.errorCode = "INVALID_POSTCODE";
                  expect(subject.formatPostcodeStatus(status)).to.throw(Error);
              });
          });
      });
  });
  </code></pre>
  
  <p>When I run the test above, I get the following error message:</p>
  
  <blockquote>
    <p>1) networkDataHelper #formatPostcodeStatus a request with an incorrect postcode throws an error: Error: INVALID_POSTCODE</p>
  </blockquote>
  
  <p>It seems like the error that is being thrown is causing the test to fail, but I'm not too sure. Does anyone have any ideas?</p>