Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mayank1513 committed Feb 24, 2024
1 parent 69455eb commit cdd30f3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
21 changes: 19 additions & 2 deletions lib/nthul/src/server/server-target/server-target.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { cleanup, render, screen } from "@testing-library/react";
import { afterEach, describe, test } from "vitest";
import { ServerTarget } from "./server-target";
import { DEFAULT_ID } from "../../constants";
import { ServerTarget } from "./server-target";

describe("server-target", () => {
afterEach(cleanup);
Expand All @@ -25,6 +25,23 @@ describe("server-target", () => {
},
};
render(<ServerTarget />);
expect(screen.getByTestId("server-target").className).toBe(`th-${THEME} ${COLOR_SCHEME}`);
expect(screen.getByTestId("server-target").className).toBe(`th-${THEME} ${COLOR_SCHEME} `);
});

test("test classes from styles", ({ expect }) => {
const THEME = "my-theme";
const COLOR_SCHEME = "dark";
globalThis.cookies = {
[DEFAULT_ID]: {
value: `${THEME},${COLOR_SCHEME}`,
},
};
const styles = {
[THEME]: `moduled-${THEME}`,
dark: `moduled-dark`,
light: `moduled-light`,
};
render(<ServerTarget styles={styles} />);
expect(screen.getByTestId("server-target").className).toBe(`th-${styles[THEME]} ${styles[COLOR_SCHEME]} `);
});
});
2 changes: 1 addition & 1 deletion lib/nthul/src/server/server-target/server-target.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function ServerTarget({ tag, targetId, styles }: ServerTargetProps) {
if (styles) {
theme = styles[theme];
cs = styles[cs];
specificity = styles[specificity];
specificity = styles[specificity] ?? "";
}

const cls = `th-${theme} ${cs} ${specificity}`;
Expand Down

0 comments on commit cdd30f3

Please sign in to comment.