By looking at this question, I failed to find the answer to my current problem:
I have a custom exception (designed according to this guide):
let StrictOverwrite_destination_error = function(message) {
var error = new Error(message);
error.name = "utils_misc.StrictOverwrite_destination_error";
throw error;
};
which I throw from the function strictOverwrite
:
function strictOverwrite ( destination, source, debug ) {
// lots of code snipped
else if ( !destination.hasOwnProperty( property ) && source.hasOwnProperty( property ) )
{
throw new StrictOverwrite_destination_error(
"source.property exists, but destination.property doesn't" );
}
// more code snipped
return destination;
}
Both the error and the function is defined in my module utils_misc
, although my custom exception definition isn't exported from the namespace.
This is how I test exception throwing from my strictOverwrite
function:
assert.throws(
function() {
utils_misc.strictOverwrite(c, c_dominator, false);
},
function(error) {
return error.name === "utils_misc.StrictOverwrite_destination_error";
}
);
but, alas, Qunit isn't satisfied:
Expected:
function( a ){
[code]
}
Result:
{
"message": "property is not defined",
"name": "ReferenceError"
}
Diff:
function( a ){
[code]{
"message": "property is not defined",
"name": "ReferenceError"
}
Apart from the whole thing not working, one thing that puzzles me is how Qunit acquired this message: "property is not defined"
. That's not exactly the message produced by my custom StrictOverwrite_destination_error
exception.