Skip to content

Commit

Permalink
Adds unit tests for UpwardServerError.js (#868)
Browse files Browse the repository at this point in the history
  • Loading branch information
supernova-at authored Feb 11, 2019
1 parent b202eb6 commit 4a042e7
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/upward-js/lib/UpwardServerError.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ class UpwardServerError extends Error {
}
constructor(originalError, message) {
super(originalError);
this.message += ' -- ' + message;

if (message) {
this.message += ' -- ' + message;
}
}
}

Expand Down
58 changes: 58 additions & 0 deletions packages/upward-js/lib/__tests__/UpwardServerError.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import UpwardServerError from '../UpwardServerError';

const MOCK_ERROR_MESSAGE = 'Unit Test';
const MOCK_ERROR = new Error(MOCK_ERROR_MESSAGE);
const MOCK_ADDITIONAL_MESSAGE = 'Additional Unit Test Message';

describe('class', () => {
test('it is of type Error', () => {
const result = new UpwardServerError(
MOCK_ERROR,
MOCK_ADDITIONAL_MESSAGE
);

expect(result).toBeInstanceOf(Error);
});

test('it can accept an error object as its first argument', () => {
const result = new UpwardServerError(MOCK_ERROR);

expect(result).toBeInstanceOf(Error);
});

test('it can accept a string as its first argument', () => {
const result = new UpwardServerError(MOCK_ERROR_MESSAGE);

expect(result).toBeInstanceOf(Error);
});
});

describe('name', () => {
test('it equals "UpwardServerError"', () => {
const result = new UpwardServerError(
MOCK_ERROR,
MOCK_ADDITIONAL_MESSAGE
);

expect(result.name).toBe('UpwardServerError');
});
});

describe('message', () => {
test('it appends a custom message to the original error', () => {
const result = new UpwardServerError(
MOCK_ERROR,
MOCK_ADDITIONAL_MESSAGE
);

expect(result.message).toEqual(
`Error: ${MOCK_ERROR_MESSAGE} -- ${MOCK_ADDITIONAL_MESSAGE}`
);
});

test('it does not append a custom message if one is not present', () => {
const result = new UpwardServerError(MOCK_ERROR);

expect(result.message).toEqual(`Error: ${MOCK_ERROR_MESSAGE}`);
});
});

1 comment on commit 4a042e7

@vercel
Copy link

@vercel vercel bot commented on 4a042e7 Feb 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully aliased the URL https://magento-venia-zntyefimvd.now.sh to the following aliases.

Please sign in to comment.