0

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.

  • 1
    I'm pretty sure your code is throwing a different Error (a `ReferenceError`) before it ever hits that line with your custom error being thrown. I'd suggest logging out the full `error` object in your test to see what file and line number the error is coming from. – Jordan Kasper Dec 15 '17 at 19:30
  • 1
    I think you're right! Revisiting the test code today, it worked as soon as I took it out from its comment, into the code. I must have fixed the bug in the application code in the meantime. –  Dec 18 '17 at 20:47

1 Answers1

0

The test code written in this question works just right. The issue was in the application code being tested.