Skip to content

Commit 4d08435

Browse files
committed
[CHORE] message-parser: add test coverage for isNodeOfType guard
1 parent 4f43a85 commit 4d08435

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@rocket.chat/message-parser": patch
3+
---
4+
5+
Add test coverage for isNodeOfType guard bringing branch coverage to 100%
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { isNodeOfType } from '../src/guards';
2+
3+
describe('isNodeOfType', () => {
4+
it('returns true when value has matching type', () => {
5+
expect(isNodeOfType({ type: 'PLAIN_TEXT', value: 'hi' }, 'PLAIN_TEXT')).toBe(true);
6+
});
7+
8+
it('returns false for null', () => {
9+
expect(isNodeOfType(null, 'PLAIN_TEXT')).toBe(false);
10+
});
11+
12+
it('returns false for non-object', () => {
13+
expect(isNodeOfType('string', 'PLAIN_TEXT')).toBe(false);
14+
});
15+
16+
it('returns false when type does not match', () => {
17+
expect(isNodeOfType({ type: 'BOLD', value: [] }, 'PLAIN_TEXT')).toBe(false);
18+
});
19+
20+
it('returns false when type property is missing', () => {
21+
expect(isNodeOfType({ value: 'hi' }, 'PLAIN_TEXT')).toBe(false);
22+
});
23+
24+
it('returns false for undefined', () => {
25+
expect(isNodeOfType(undefined, 'PLAIN_TEXT')).toBe(false);
26+
});
27+
});

0 commit comments

Comments
 (0)