Skip to content

Commit 99a07e8

Browse files
committed
test: add unit tests for hiddenElements utility for markdownUtils.ts file
1 parent a822963 commit 99a07e8

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { hiddenElements } from '~/lib/markdownUtils';
2+
3+
type HiddenComponents = Record<string, { component: () => null }>;
4+
5+
// Describe what we're testing
6+
describe('hiddenElements', () => {
7+
// Test 1: Basic functionality
8+
it('creates an object with a component for each element name', () => {
9+
// Arrange: What we're testing with
10+
const elementNames = ['Header', 'Footer', 'Sidebar'];
11+
12+
// Act: Call the function
13+
const result = hiddenElements(...elementNames) as HiddenComponents;
14+
15+
// Assert: Check the result
16+
// Should have 3 keys
17+
expect(Object.keys(result)).to.have.length(3);
18+
19+
// Each key should exist
20+
expect(result).to.have.property('Header');
21+
expect(result).to.have.property('Footer');
22+
expect(result).to.have.property('Sidebar');
23+
24+
// Each value should have a component function
25+
expect(result.Header).to.have.property('component');
26+
expect(result.Header.component).to.be.a('function');
27+
28+
// Component should return null
29+
expect(result.Header.component()).to.be.null;
30+
});
31+
32+
it('returns empty object when no elements provided', () => {
33+
const result = hiddenElements();
34+
expect(result).to.deep.equal({});
35+
});
36+
37+
it('handles single element', () => {
38+
const result = hiddenElements('Navbar') as Record<
39+
string,
40+
{ component: () => null }
41+
>;
42+
expect(Object.keys(result)).to.have.length(1);
43+
expect(result.Navbar.component()).to.be.null;
44+
});
45+
});

0 commit comments

Comments
 (0)