diff options
| author | Filip Wandzio <contact@philw.dev> | 2025-11-02 01:44:05 +0100 |
|---|---|---|
| committer | Filip Wandzio <contact@philw.dev> | 2025-11-02 01:44:05 +0100 |
| commit | ba940047eb099fc18315d4cafd55300995a76894 (patch) | |
| tree | db4ae932ba798f0f15d3648d9950c05c6eae5b7e /src | |
| parent | d1fec5cf2df51c5260bbe877672a55d86de68b0d (diff) | |
| download | philw.dev-ba940047eb099fc18315d4cafd55300995a76894.tar.gz philw.dev-ba940047eb099fc18315d4cafd55300995a76894.zip | |
Implement unit testing with vitest
Signed-off-by: Filip Wandzio <contact@philw.dev>
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/App.test.ts | 8 | ||||
| -rw-r--r-- | src/test/Main.test.ts | 45 | ||||
| -rw-r--r-- | src/test/setupTests.ts (renamed from src/setupTests.ts) | 0 |
3 files changed, 53 insertions, 0 deletions
diff --git a/src/test/App.test.ts b/src/test/App.test.ts new file mode 100644 index 0000000..64fae7d --- /dev/null +++ b/src/test/App.test.ts | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | import { render } from '@testing-library/svelte'; | ||
| 2 | import App from '../App.svelte'; | ||
| 3 | |||
| 4 | describe('App component', () => { | ||
| 5 | test('it renders the App component', () => { | ||
| 6 | render(App); | ||
| 7 | }); | ||
| 8 | }); | ||
diff --git a/src/test/Main.test.ts b/src/test/Main.test.ts new file mode 100644 index 0000000..1fdd1e2 --- /dev/null +++ b/src/test/Main.test.ts | |||
| @@ -0,0 +1,45 @@ | |||
| 1 | import { render, screen } from '@testing-library/svelte'; | ||
| 2 | import Main from '../lib/components/Main.svelte'; | ||
| 3 | |||
| 4 | describe('Main component', () => { | ||
| 5 | test('it renders the Projects section with the correct heading and content', () => { | ||
| 6 | render(Main); | ||
| 7 | |||
| 8 | const projectsHeading = screen.getByText('Projects'); | ||
| 9 | expect(projectsHeading).toBeInTheDocument(); | ||
| 10 | |||
| 11 | const projectText = screen.getByText(/git repository/i); | ||
| 12 | expect(projectText).toBeInTheDocument(); | ||
| 13 | |||
| 14 | const link = screen.getByRole('link', { name: /git repository/i }); | ||
| 15 | expect(link).toHaveAttribute('href', 'https://git.philw.dev'); | ||
| 16 | expect(link).toHaveAttribute('target', '_blank'); | ||
| 17 | }); | ||
| 18 | |||
| 19 | test('it renders the Contact section with the correct heading and content', () => { | ||
| 20 | render(Main); | ||
| 21 | |||
| 22 | const contactHeading = screen.getByText('Contact'); | ||
| 23 | expect(contactHeading).toBeInTheDocument(); | ||
| 24 | |||
| 25 | const emailLink = screen.getByRole('link', { name: /email filip wandzio/i }); | ||
| 26 | expect(emailLink).toHaveAttribute('href', 'mailto:contact@philw.dev'); | ||
| 27 | |||
| 28 | const matrixLink = screen.getByRole('link', { name: /filip wandzio matrix account/i }); | ||
| 29 | expect(matrixLink).toHaveAttribute('href', 'https://matrix.to/#/@philw:matrix.philw.dev'); | ||
| 30 | }); | ||
| 31 | |||
| 32 | test('it has the correct aria-labelledby attributes for accessibility', () => { | ||
| 33 | render(Main); | ||
| 34 | |||
| 35 | // Ensure sections are correctly labeled for accessibility | ||
| 36 | const aboutSection = screen.getByRole('region', { name: /about/i }); | ||
| 37 | expect(aboutSection).toHaveAttribute('aria-labelledby', 'about-heading'); | ||
| 38 | |||
| 39 | const projectsSection = screen.getByRole('region', { name: /projects/i }); | ||
| 40 | expect(projectsSection).toHaveAttribute('aria-labelledby', 'projects-heading'); | ||
| 41 | |||
| 42 | const contactSection = screen.getByRole('region', { name: /contact/i }); | ||
| 43 | expect(contactSection).toHaveAttribute('aria-labelledby', 'contact-heading'); | ||
| 44 | }); | ||
| 45 | }); | ||
diff --git a/src/setupTests.ts b/src/test/setupTests.ts index c44951a..c44951a 100644 --- a/src/setupTests.ts +++ b/src/test/setupTests.ts | |||
