Skip to content

Commit

Permalink
Merge 79a5b30 into 9d791a9
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeaudry committed Aug 19, 2018
2 parents 9d791a9 + 79a5b30 commit e9ea8a3
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 5 deletions.
4 changes: 3 additions & 1 deletion index.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import Model from './src/Model';
import Collection from './src/Collection';
import Enum from './src/Enum';
import Serializable from './src/Serializable';
import ErrorFactory from './src/ErrorFactory';

export {
Model,
Collection,
Enum,
Serializable
Serializable,
ErrorFactory
}
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ const Model = require('./lib/Model');
const Collection = require('./lib/Collection');
const Enum = require('./lib/Enum');
const Serializable = require('./lib/Serializable');
const ErrorFactory = require('./lib/ErrorFactory');

module.exports = {
Model: Model.default,
Collection: Collection.default,
Enum: Enum.default,
Serializable: Serializable.default
Serializable: Serializable.default,
ErrorFactory: ErrorFactory.default
}
3 changes: 2 additions & 1 deletion index.mjs
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';
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "metamon",
"version": "2.3.0",
"version": "2.4.0",
"description": "model, and collection library for class based or pojo models",
"main": "index.js",
"browser": "dist/metamon.min.js",
Expand Down
17 changes: 17 additions & 0 deletions src/ErrorFactory.js
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);
}
}
}
21 changes: 21 additions & 0 deletions tests/errorfactor.spec.js
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);
});

0 comments on commit e9ea8a3

Please sign in to comment.