Skip to content

Commit 68d08cc

Browse files
Samantha-KYserapieTuyishime
authored andcommitted
feat: add test for the theme wrapper
1 parent c88b399 commit 68d08cc

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

__mocks__/colors.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export const colors = {
2+
textAccent: "--tm-text",
3+
text: "--tm-text",
4+
accent: "--tm-accent",
5+
primary: "--tm-primary",
6+
secondary: "--tm-secondary",
7+
highlight: "--tm-highlight",
8+
muted: "--tm-muted",
9+
cover: {
10+
text: "--tm-text",
11+
accent: "--tm-accent",
12+
primary: "--tm-primary",
13+
background: "--tm-background"
14+
}
15+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import ThemeWrapper from "@/components/wrappers/ThemeWrapper";
2+
import "@testing-library/jest-dom";
3+
import { render, screen } from "@testing-library/react";
4+
import { colors } from "../../../__mocks__/colors";
5+
6+
describe("ThemeWrapper", () => {
7+
it("should render the theme", () => {
8+
render(<ThemeWrapper>Theme wrapper</ThemeWrapper>);
9+
const themeWrapper = screen.getByTestId("themeWrapper");
10+
11+
expect(themeWrapper).toBeInTheDocument();
12+
expect(themeWrapper.textContent).toBe("Theme wrapper");
13+
});
14+
15+
it("should apply extra props", () => {
16+
render(<ThemeWrapper colors={colors}>Theme wrapper</ThemeWrapper>);
17+
const themeWrapper = screen.getByTestId("themeWrapper");
18+
19+
expect(themeWrapper.style.cssText).toContain("--tm-");
20+
});
21+
});

src/components/wrappers/ThemeWrapper.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export default function ThemeWrapper({ colors, className = "", children }: Theme
5252
}, [colors]);
5353

5454
return (
55-
<div className={className} style={{ ...cssVars }}>
55+
<div className={className} style={{ ...cssVars }} data-testid="themeWrapper">
5656
{children}
5757
</div>
5858
);

0 commit comments

Comments
 (0)