Skip to content

Commit ab49532

Browse files
committed
test: update Sidebar tests to render text content and improve test wrapper logic
1 parent f075059 commit ab49532

4 files changed

Lines changed: 8 additions & 7 deletions

File tree

src/lib/component/Sidebar.svelte.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,14 @@ describe('Sidebar', () => {
4444
expect(sidebar?.textContent?.trim()).toBe('');
4545
});
4646

47-
it('renders multiple child elements', () => {
47+
it('renders text content', () => {
4848
const { container } = render(SidebarWrapper, {
4949
props: {
50-
content: '<div>Item 1</div><div>Item 2</div>'
50+
content: 'Multiple items in sidebar'
5151
}
5252
});
5353

5454
const sidebar = container.querySelector('.sidebar');
55-
expect(sidebar?.textContent).toContain('Item 1');
56-
expect(sidebar?.textContent).toContain('Item 2');
55+
expect(sidebar?.textContent).toContain('Multiple items in sidebar');
5756
});
5857
});

src/lib/component/Sidebar.test-wrapper.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66

77
<Sidebar>
88
{#if content}
9-
{@html content}
9+
{content}
1010
{/if}
1111
</Sidebar>

src/test-setup/client-setup.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ const localStorageMock = {
6262
getItem: vi.fn(),
6363
setItem: vi.fn(),
6464
removeItem: vi.fn(),
65-
clear: vi.fn()
65+
clear: vi.fn(),
66+
length: 0,
67+
key: vi.fn()
6668
};
6769
global.localStorage = localStorageMock as Storage;

src/test-setup/setup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { vi } from 'vitest';
77

88
// Ensure we're in a browser-like environment for Svelte 5
99
if (typeof globalThis !== 'undefined') {
10-
// @ts-ignore
10+
// @ts-expect-error - Adding browser flag for Svelte 5 testing
1111
globalThis.browser = true;
1212
}
1313

0 commit comments

Comments
 (0)