Skip to content

Commit

Permalink
feat(eerror): Add main code and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CheerlessCloud committed Aug 12, 2017
1 parent 2116f15 commit 1d5d558
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class EError extends Error {
constructor(message, ...args) {
super(message);
this.name = 'EError';

for (let i = 0; i < args.length; i += 1) {
if (typeof args[i] === 'object') {
Object.assign(this, args[i]);
} else {
this[`param${i + 1}`] = args[i];
}
}
}
}

module.exports = EError;
12 changes: 12 additions & 0 deletions src/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import test from 'ava';
import EError from './index';

test('eerror - smoke test', (t) => {
t.notThrows(() => {
const error = new EError('Message', 'val1', { success: true });
t.true(error instanceof Error);
t.is(typeof error.stack, 'string');
t.is(error.param1, 'val1');
t.is(error.success, true);
});
});

0 comments on commit 1d5d558

Please sign in to comment.