Skip to content

Commit

Permalink
feat (test): write unit tests for Footer (#249)
Browse files Browse the repository at this point in the history
* feat (test): write unit tests for Footer

* chore: update playwright config to only run *.spec.js files
  • Loading branch information
alvyynm authored Oct 15, 2024
1 parent 95aefbb commit a211f13
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions playwright.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { defineConfig, devices } from "@playwright/test";
*/
module.exports = defineConfig({
testDir: "./tests",
testMatch: "**/*.spec.js", // only run *.spec.js files
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
Expand Down
28 changes: 28 additions & 0 deletions tests/components/Footer.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { render, screen } from "@testing-library/react";
import { BrowserRouter } from "react-router-dom";
import { describe, expect, it } from "vitest";
import Footer from "../../src/components/Footer";

describe("Footer", () => {
const renderWithRouter = (ui) => render(<BrowserRouter>{ui}</BrowserRouter>);

it("should render successfully", () => {
renderWithRouter(<Footer />);
expect(screen.getByRole("contentinfo")).toBeTruthy();
});

it("displays correct copyright notice", () => {
renderWithRouter(<Footer />);
expect(
screen.getByText((content) =>
content.includes(" SpaceYaTech | All Rights Reserved")
)
).toBeTruthy();
});

it("renders correct number of links", () => {
renderWithRouter(<Footer />);
const links = screen.getAllByRole("link");
expect(links).toHaveLength(15);
});
});

0 comments on commit a211f13

Please sign in to comment.