Skip to content

Commit a211f13

Browse files
authored
feat (test): write unit tests for Footer (#249)
* feat (test): write unit tests for Footer * chore: update playwright config to only run *.spec.js files
1 parent 95aefbb commit a211f13

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

playwright.config.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { defineConfig, devices } from "@playwright/test";
1212
*/
1313
module.exports = defineConfig({
1414
testDir: "./tests",
15+
testMatch: "**/*.spec.js", // only run *.spec.js files
1516
/* Run tests in files in parallel */
1617
fullyParallel: true,
1718
/* Fail the build on CI if you accidentally left test.only in the source code. */

tests/components/Footer.test.jsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { render, screen } from "@testing-library/react";
2+
import { BrowserRouter } from "react-router-dom";
3+
import { describe, expect, it } from "vitest";
4+
import Footer from "../../src/components/Footer";
5+
6+
describe("Footer", () => {
7+
const renderWithRouter = (ui) => render(<BrowserRouter>{ui}</BrowserRouter>);
8+
9+
it("should render successfully", () => {
10+
renderWithRouter(<Footer />);
11+
expect(screen.getByRole("contentinfo")).toBeTruthy();
12+
});
13+
14+
it("displays correct copyright notice", () => {
15+
renderWithRouter(<Footer />);
16+
expect(
17+
screen.getByText((content) =>
18+
content.includes(" SpaceYaTech | All Rights Reserved")
19+
)
20+
).toBeTruthy();
21+
});
22+
23+
it("renders correct number of links", () => {
24+
renderWithRouter(<Footer />);
25+
const links = screen.getAllByRole("link");
26+
expect(links).toHaveLength(15);
27+
});
28+
});

0 commit comments

Comments
 (0)