JavaScript qunit - test exception message? junit test exception message,java junit test exception message,junit

So QUnit provides the "raise" assertion to test if an exception is thrown. Is there any way to test the actual message thrown by the exception, though? For instance, say I have this function:

throwError = function(arg) {
  var err = new Error();
  if (typeof arg === 'undefined') {
    err.message = 'missing parameter';
    throw err;
  }
}

I'd like to be able to write something along these lines:

raises(
  function(){throwError();},
  Error.message,
  'missing arg'
);

Ideally, this test would fail because the exception message is "missing parameter" and I expect it to be "missing arg," but it passes because qunit only checks that an error was raised. Any way to check the actual contents of the thrown exception?

Answer:1

I need a mechanism for storing complex data structures created in client side javascript. I've been considering using the stringify method to convert the javascript object into a string, store it in ...

I need a mechanism for storing complex data structures created in client side javascript. I've been considering using the stringify method to convert the javascript object into a string, store it in ...

If I have an arbitrary function myFunc, what I'm aiming to do is replace this function with a wrapped call that runs code before and after it executes, e.g. // note: psuedo-javascript var ...

If I have an arbitrary function myFunc, what I'm aiming to do is replace this function with a wrapped call that runs code before and after it executes, e.g. // note: psuedo-javascript var ...

Question What's the full code to enable jQuery on a page and then use it to replace the contents of a DIV with HTML text from an external file? Background I'm brand new to jQuery and I'm eager to ...

Question What's the full code to enable jQuery on a page and then use it to replace the contents of a DIV with HTML text from an external file? Background I'm brand new to jQuery and I'm eager to ...

  1. jquery replace div contents with html

How do I load another page on the onClick event in Javascript? <div id="div_man" onclick="/subfolder/index.htm"></div> The code above is not working. Please explain. I am sure it's quite ...

How do I load another page on the onClick event in Javascript? <div id="div_man" onclick="/subfolder/index.htm"></div> The code above is not working. Please explain. I am sure it's quite ...