Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
  • Loading branch information
yukukotani committed Oct 14, 2024
1 parent 9065029 commit b59c216
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
11 changes: 11 additions & 0 deletions src/__snapshots__/styled.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`styled > renders dynamic style 1`] = `".j1dqz { color: red; }"`;

exports[`styled > renders dynamic style 2`] = `".jyt81 { gap: var(--j-spaces-md); }"`;

exports[`styled > renders dynamic style 3`] = `".j1o5l { background-color: gray; }"`;

exports[`styled > renders style tag in head 1`] = `".j1dqz { color: red; }"`;

exports[`styled > renders style tag in head 2`] = `".jyt81 { gap: var(--j-spaces-md); }"`;
27 changes: 16 additions & 11 deletions src/styled.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@ describe("styled", async () => {
test("renders style tag in head", async () => {
const RedDiv = styled("div", {
color: "red",
gap: "$spaces.md",
});

render(<RedDiv data-testid="red-div">RedDiv</RedDiv>);

await waitFor(() => {
const styleTag = Array.from(document.getElementsByTagName("style")).find(
(e) => e.dataset.href != null,
);
expect(styleTag).toBeDefined();
// biome-ignore lint/style/noNonNullAssertion: <explanation>
expect(document.head).toContainElement(styleTag!);
expect(styleTag).toHaveAttribute("data-precedence", "medium");
expect(styleTag).not.toBeEmptyDOMElement();
const styleTags = Array.from(
document.getElementsByTagName("style"),
).filter((e) => e.dataset.href != null);
expect(styleTags).toHaveLength(2);
for (const styleTag of styleTags) {
expect(document.head).toContainElement(styleTag);
expect(styleTag).toHaveAttribute("data-precedence", "medium");
expect(styleTag.textContent).toMatchSnapshot();
}
});
});

Expand All @@ -29,7 +31,10 @@ describe("styled", async () => {
});

render(
<RedDiv data-testid="red-div" style={{ backgroundColor: "gray" }}>
<RedDiv
data-testid="red-div"
style={{ backgroundColor: "gray", gap: "$spaces.md" }}
>
RedDiv
</RedDiv>,
);
Expand All @@ -38,11 +43,11 @@ describe("styled", async () => {
const styleTags = Array.from(
document.getElementsByTagName("style"),
).filter((e) => e.dataset.href != null);
expect(styleTags).toHaveLength(2);
expect(styleTags).toHaveLength(3);
for (const styleTag of styleTags) {
expect(document.head).toContainElement(styleTag);
expect(styleTag).toHaveAttribute("data-precedence", "medium");
expect(styleTag).not.toBeEmptyDOMElement();
expect(styleTag.textContent).toMatchSnapshot();
}
});
});
Expand Down

0 comments on commit b59c216

Please sign in to comment.