Using QUinit's throw() assertion I want to test that an error is thrown and the error message. I have the following function:
/**
 * Error function for Node.
 * @param {String} msg Error message.
 */
function NodeError (msg) {
  var that = this
  /**
   * Attribute for message.
   * @type {String}
   */
  this.msg = msg
  /**
   * Function rendering NodeError as a string.
   * @return {String} String representation of NodeError.
   */
  this.toString = function () {
    return that.msg
  }
}
/**
 * Node object. TODO Fill out.
 * @param {String} title Node title.
 * @throws {NodeError} If no title given
 */
function Node (title) {
  var that = this
  if (!title) {
    throw new Error('Error: no title given')
  }
  /**
   * Node title
   * @type {[type]}
   */
  this.title = title
}
And the following QUnit test:
QUnit.test('new Node w/o title throws error', function (assert) {
  assert.expect(1) // Expected number of assertions
  assert.throws(
    function () { new Node() },
    function (err) { err.toString() === 'Error: no title given' },
    'Error thrown'
  )
})
However, the Unit tests fails giving this:
Error thrown@ 0 ms
Expected:   
function( a ){
  [code]
}
Result:     
Error("Error: no title given")
Diff:   
function( a ){
  [code]
}Error("Error: no title given")
Source:     
    at Object.<anonymous> (file:///Users/maasha/install/src/protwiz/test/test_pw_node.js:10:10)
What to do?
 
     
    