Skip to content

Commit

Permalink
add unit tests (#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
mfix-stripe committed Nov 2, 2022
1 parent 411e84e commit cdda395
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/tag.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Tag from './tag';

describe('Tag.isTag', function () {
it('should detect when value is not a tag', () => {
expect(Tag.isTag(undefined)).toBe(false);
expect(Tag.isTag(null)).toBe(false);
expect(Tag.isTag('')).toBe(false);
expect(Tag.isTag(8)).toBe(false);
expect(Tag.isTag(true)).toBe(false);
expect(Tag.isTag([])).toBe(false);
expect(Tag.isTag({ my: 'object' })).toBe(false);
});

it('should detect tags', () => {
expect(Tag.isTag(new Tag('tag', {}, []))).toBe(true);
});
});
2 changes: 1 addition & 1 deletion src/tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default class Tag<
readonly $$mdtype = 'Tag' as const;

static isTag = (tag: any): tag is Tag => {
return '$$mdtype' in tag && tag.$$mdtype === 'Tag';
return !!(tag?.$$mdtype === 'Tag');
};

name: N;
Expand Down

0 comments on commit cdda395

Please sign in to comment.