From b4f398ec6a430ae994216536636ab555abc1dc87 Mon Sep 17 00:00:00 2001 From: Katharina Irrgang Date: Thu, 14 Dec 2017 03:36:50 +0100 Subject: [PATCH] Tidy up unit test files (#9340) refs #9178 - first iteration of tidying up the unit tests - this is useful in the current stage, because if i move files in the server folder, i need a clean folder/file structure to detect which tests needs to move - this is a simple cleanup to reflect the current server folder structure --- ghost/errors/test/errors.test.js | 70 ++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 ghost/errors/test/errors.test.js diff --git a/ghost/errors/test/errors.test.js b/ghost/errors/test/errors.test.js new file mode 100644 index 0000000000..7ece018df1 --- /dev/null +++ b/ghost/errors/test/errors.test.js @@ -0,0 +1,70 @@ +var should = require('should'), // jshint ignore:line + common = require('../../../../server/lib/common'); + +describe('Errors', function () { + it('Ensure we inherit from Error', function () { + var ghostError = new common.errors.GhostError(); + (ghostError instanceof Error).should.eql(true); + }); + + describe('Inherite from other error', function () { + it('default', function () { + var someError = new Error(), ghostError; + + someError.message = 'test'; + someError.context = 'test'; + someError.help = 'test'; + + ghostError = new common.errors.GhostError({err: someError}); + ghostError.stack.should.match(/Error: test/); + ghostError.context.should.eql(someError.context); + ghostError.help.should.eql(someError.help); + }); + + it('has nested object', function () { + var someError = new Error(), ghostError; + + someError.obj = { + a: 'b' + }; + + ghostError = new common.errors.GhostError({ + err: someError + }); + + ghostError.obj.should.eql(someError.obj); + }); + + it('with custom attribute', function () { + var someError = new Error(), ghostError; + + someError.context = 'test'; + + ghostError = new common.errors.GhostError({ + err: someError, + context: 'context' + }); + + ghostError.context.should.eql('test'); + }); + + it('with custom attribute', function () { + var someError = new Error(), ghostError; + + ghostError = new common.errors.GhostError({ + err: someError, + message: 'test' + }); + + ghostError.message.should.eql('test'); + }); + + it('error is string', function () { + var ghostError = new common.errors.GhostError({ + err: 'string' + }); + + ghostError.stack.should.match(/Error: string/); + }); + }); +});