Skip to content

Commit

Permalink
test: exercise the new generic
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Nov 20, 2023
1 parent 49beee5 commit 93e6a3f
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/unit/sfErrorTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,29 @@ describe('SfError', () => {
});
});

describe('generic for data', () => {
class ErrorWithBooleanData extends SfError<boolean> {}
it('should accept a generic for data and allow a valid set', () => {
const err = new ErrorWithBooleanData('test');
err.setData(true);
expect(err.data).to.equal(true);
});

it('should not allow an invalid set', () => {
const err = new ErrorWithBooleanData('test');
// @ts-expect-error invalid boolean
err.setData(5);
// @ts-expect-error invalid boolean
err.setData('foo');
});

it('should allow anything on the original unknown', () => {
const err = new SfError('test');
err.setData(5);
err.setData('foo');
err.setData({ bar: 6 });
});
});
describe('toObject', () => {
it('should return the proper JSON object WITH context and data', () => {
const message = 'its a trap!';
Expand Down

0 comments on commit 93e6a3f

Please sign in to comment.