-
Notifications
You must be signed in to change notification settings - Fork 683
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds unit tests for UpwardServerError.js (#868)
- Loading branch information
1 parent
b202eb6
commit 4a042e7
Showing
2 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
packages/upward-js/lib/__tests__/UpwardServerError.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
}); | ||
}); |
4a042e7
There was a problem hiding this comment.
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.