-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
48 additions
and
5 deletions.
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
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
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export Model from './src/Model'; | ||
export Collection from './src/Collection'; | ||
export Enum from './src/Enum'; | ||
export Serializable from './src/Serializable'; | ||
export Serializable from './src/Serializable'; | ||
export ErrorFactory from './src/ErrorFactory'; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,17 @@ | ||
/** | ||
* | ||
* construct a custom error constructor and streamline | ||
* the stack trace captured in the custom error | ||
* | ||
* @param {ErrorConstructor} (ErrorClass) [Error] | ||
* @returns {Error} | ||
* | ||
*/ | ||
export default function ErrorFactory(ErrorClass=Error) { | ||
return class CustomError extends ErrorClass { | ||
constructor(...args) { | ||
super(...args); | ||
Error.captureStackTrace(this, CustomError); | ||
} | ||
} | ||
} |
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,21 @@ | ||
import test from 'ava'; | ||
import faker from 'faker'; | ||
import ErrorFactory from '../src/ErrorFactory'; | ||
|
||
test.beforeEach(t => { | ||
const text = faker.random.word(); | ||
const ErrorConstructor = ErrorFactory(); | ||
const Error = new ErrorConstructor(text); | ||
t.context = { | ||
ErrorConstructor, | ||
Error, | ||
text | ||
}; | ||
}); | ||
|
||
test('ErrorFactory() should return an Error Constructor', t => { | ||
t.is(typeof ErrorFactory, 'function'); | ||
t.is(typeof t.context.ErrorConstructor, 'function'); | ||
t.is(typeof t.context.Error, 'object'); | ||
t.is(t.context.Error.message, t.context.text); | ||
}); |