Skip to content

Commit

Permalink
test: added test case for the new isErrorWithCode helper.
Browse files Browse the repository at this point in the history
  • Loading branch information
rpl committed Aug 18, 2016
1 parent ea8700e commit 406aadc
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion tests/test.errors.js
Expand Up @@ -2,7 +2,9 @@
import {describe, it} from 'mocha';
import {assert} from 'chai';

import {onlyErrorsWithCode, onlyInstancesOf} from '../src/errors';
import {
onlyErrorsWithCode, isErrorWithCode, onlyInstancesOf,
} from '../src/errors';
import {makeSureItFails} from './helpers';


Expand Down Expand Up @@ -78,4 +80,29 @@ describe('errors', () => {

});

describe('isErrorWithCode', () => {
class ErrorWithCode extends Error {
code: string;
constructor() {
super('pretend this is a system error');
this.code = 'SOME_CODE';
}
}

it('returns true on errors that do match the code', () => {
assert.equal(isErrorWithCode('SOME_CODE', new ErrorWithCode()), true);
assert.equal(
isErrorWithCode(['SOME_CODE', 'OTHER_CODE'], new ErrorWithCode()), true
);
});

it('returns false on errors that do not match the code', () => {
assert.equal(isErrorWithCode('OTHER_CODE', new ErrorWithCode()), false);
assert.equal(
isErrorWithCode(['OTHER_CODE', 'ANOTHER_CODE'], new ErrorWithCode()),
false
);
assert.equal(isErrorWithCode('ANY_CODE', new Error()), false);
});
});
});

0 comments on commit 406aadc

Please sign in to comment.