2
1
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2023-12-13 21:00:40 +01:00

Merge pull request #1831 from schneidmaster/fix-1827

Added handling for undefined errors and test coverage
This commit is contained in:
Hannah Wolfe 2014-01-04 08:42:02 -08:00
commit 9f17361bf5
2 changed files with 85 additions and 1 deletions

View file

@ -56,7 +56,11 @@ errors = {
logError: function (err, context, help) {
var stack = err ? err.stack : null;
err = err.message || err || 'Unknown';
if (err) {
err = err.message || err || 'An unknown error occurred.';
} else {
err = 'An unknown error occurred.';
}
// TODO: Logging framework hookup
// Eventually we'll have better logging which will know about envs
if ((process.env.NODE_ENV === 'development' ||

View file

@ -115,6 +115,86 @@ describe("Error handling", function () {
logStub.lastCall.calledWith('').should.be.true;
});
it("logs errors from an undefined error argument", function () {
var message = "Testing";
errors.logError(undefined, message, message);
// Calls log with message on Error objects
logStub.callCount.should.equal(4);
logStub.firstCall.calledWith("\nERROR:".red, "An unknown error occurred.".red).should.be.true;
logStub.secondCall.calledWith(message.white).should.be.true;
logStub.thirdCall.calledWith(message.green).should.be.true;
logStub.lastCall.calledWith('').should.be.true;
});
it("logs errors from an undefined context argument", function () {
var message = "Testing";
errors.logError(message, undefined, message);
// Calls log with message on Error objects
logStub.callCount.should.equal(3);
logStub.firstCall.calledWith("\nERROR:".red, message.red).should.be.true;
logStub.secondCall.calledWith(message.green).should.be.true;
logStub.lastCall.calledWith('').should.be.true;
});
it("logs errors from an undefined help argument", function () {
var message = "Testing";
errors.logError(message, message, undefined);
// Calls log with message on Error objects
logStub.callCount.should.equal(3);
logStub.firstCall.calledWith("\nERROR:".red, message.red).should.be.true;
logStub.secondCall.calledWith(message.white).should.be.true;
logStub.lastCall.calledWith('').should.be.true;
});
it("logs errors from a null error argument", function () {
var message = "Testing";
errors.logError(null, message, message);
// Calls log with message on Error objects
logStub.callCount.should.equal(4);
logStub.firstCall.calledWith("\nERROR:".red, "An unknown error occurred.".red).should.be.true;
logStub.secondCall.calledWith(message.white).should.be.true;
logStub.thirdCall.calledWith(message.green).should.be.true;
logStub.lastCall.calledWith('').should.be.true;
});
it("logs errors from a null context argument", function () {
var message = "Testing";
errors.logError(message, null, message);
// Calls log with message on Error objects
logStub.callCount.should.equal(3);
logStub.firstCall.calledWith("\nERROR:".red, message.red).should.be.true;
logStub.secondCall.calledWith(message.green).should.be.true;
logStub.lastCall.calledWith('').should.be.true;
});
it("logs errors from a null help argument", function () {
var message = "Testing";
errors.logError(message, message, null);
// Calls log with message on Error objects
logStub.callCount.should.equal(3);
logStub.firstCall.calledWith("\nERROR:".red, message.red).should.be.true;
logStub.secondCall.calledWith(message.white).should.be.true;
logStub.lastCall.calledWith('').should.be.true;
});
it("logs promise errors and redirects", function (done) {
var def = when.defer(),
prom = def.promise,