title: QUnit testing strategy for object with init function that could throw
body: <p>I am using <a href="https://github.com/simula-innovation/qunit/tree/gas/gas" rel="nofollow noreferrer"><code>QUnit</code></a> for Google Apps Script, and am attempting unit-testing on my code base, namely on this custom spreadsheet helper function I wrote:  </p>
  
  <pre><code>function DataStoreHelper() {
    this.argNames = arguments;    // TODO: check type of arguments
    this.argIndices = new Array(this.argNames.length);
    /* takes an array of column names and assigns the indices where they can be found, to this.argIndices
     */
    this.sortColumns = function (columnNames) { 
      // for each argument name ...
      for (var j in this.argNames)
      {
          var k = 0; 
        // ... sift thru the column names ...
        for (k in columnNames) {
            // ... to find the column name that contains the argument name ...
          if (columnNames[k].toLowerCase().indexOf(this.argNames[j]) !== -1) break;
          else if (k == columnNames.length - 1) k = -1;
  
        }
        // if we found it, we write it to this.argIndices
        if (k &gt; -1) this.argIndices[j] = k;
        // otherwise, we have spreadsheet error.
        else throw new Error('Spreadsheet is missing column for constructor argument: ' + this.argNames[j]);
        Logger.log('this.argNames[%s] == %s\tthis.argIndices[%s] == %s\n',
          j, 
          this.argNames[j],
          j,
          this.argIndices[j])
      }
    }
  }
  // static const strings
  DataStoreHelper.POTHOLE_NUMBER  = 'number';
  DataStoreHelper.LATITUDE        = 'latitude';
  DataStoreHelper.LONGITUDE       = 'longitude';
  DataStoreHelper.ADDRESS         = 'address';
  DataStoreHelper.SURFACE_AREA    = 'area';
  DataStoreHelper.BAGS            = 'bags';
  DataStoreHelper.SNAPPED_TO_ROAD = 'snappedtoroad';
  DataStoreHelper.FILLED          = 'filled';
  DataStoreHelper.IMAGE_URL       = 'imageurl';
  </code></pre>
  
  <p>Note, the <code>sortColumns</code> throws exception iff it's looking for keyword in the spreadsheet columns that doesn't exist. </p>
  
  <p>I begin writing my unit-testing code: </p>
  
  <pre><code>function testDataStoreHelper() {
      // construct some DataStoreHelpers....
      /* NOTE: these should be mocks, as we are trying to test behaviour. Find out how to create mock objects */
      var customDataHelper  = new DataStoreHelper(DataStoreHelper.ADDRESS,
              DataStoreHelper.LATITUDE,
              DataStoreHelper.LONGITUDE,
              DataStoreHelper.FILLED,
              'statechange');
      var testData = {};
      module('testing PotholeDataHelper', {
          setup: function() { 
              // test setup logic goes here....
              testData = tests.DUMMY_DATA;
              testData.noLatLng = [testData.dataRow[0],
                   testData.dataRow[4]   
              ];
              // invoke helper setup here, using testData ... 
              customDataHelper.sortColumns(testData.titleRow);
          }
      })
      test("attempting to map a keyword in a spreadsheet that doesn't have a corresponding column", function(assert) { 
          assert.ok(customDataHelper.argIndices.filter(function(value) { return value === -1; }).length,
              "Somehow, there's one or more mapped keywords that shouldn't be in the spreadsheet");
      })
  }
  </code></pre>
  
  <p>As expected for this naive approach, the test(s) fail because exception was thrown in the <code>setup</code> callback. How best to test code like this, where the initialization function could throw?</p>