Is there a way to make mocha print the error object instead of the error message?

Let me give you an example.

before(function (done)
{
    ...
    testUtils.someInitWork(done);
});

testUtils = {
    someInitWork: function (done)
    {
        ...
        if (e)
            // wrap the error into another error object and add contextual information.
            e2 = errorManager.getError('myerror', e, { context: "more context for the error });
    }
};

      

when the test init code fails using a utility function, it passes the required contextual information to the error object. This error object is passed before the callback completes. mocha prints an error to the console (I'm using the reporter specifier). Instead, if I can get it to print util.inspect(e)

, this information will be more helpful in debugging the problem.

Of course, I can change the test code to print it. but is there a way to change how mocha reports the error (passed before the callback) to the console?

+3


source to share





All Articles