Skip to content

Commit 34704fb

Browse files
test(native): render the stylesheets the compiler recovers
The compiler test asserts which rules compile() keeps beside a rule lightningcss cannot parse, but nothing rendered them. Each case now renders in light and dark: the rules beside it style their elements and the rule itself styles nothing, the (prefers-color-scheme: 0) query included, whose compiled form the media compiler decides.
1 parent 03a2ef2 commit 34704fb

1 file changed

Lines changed: 58 additions & 0 deletions

File tree

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { act, render, screen } from "@testing-library/react-native";
2+
import { View } from "react-native-css/components/View";
3+
import { registerCSS } from "react-native-css/jest";
4+
import { colorScheme } from "react-native-css/runtime";
5+
6+
function styleOf(className: string) {
7+
return screen.getByTestId(className).props.style as unknown;
8+
}
9+
10+
describe("a stylesheet holding a rule lightningcss cannot parse", () => {
11+
test.each([
12+
["a media query with a <general-enclosed> condition", "@media (foo bar)"],
13+
[
14+
"a container query with a <general-enclosed> condition",
15+
"@container (foo bar)",
16+
],
17+
[
18+
"a media query with a value its feature does not take",
19+
"@media (prefers-color-scheme: 0)",
20+
],
21+
])("%s styles nothing and the rules beside it apply", (_, prelude) => {
22+
registerCSS(
23+
`.a { color: red } ${prelude} { .b { color: blue } } .c { color: green }`,
24+
);
25+
26+
render(
27+
<>
28+
<View testID="a" className="a" />
29+
<View testID="b" className="b" />
30+
<View testID="c" className="c" />
31+
</>,
32+
);
33+
34+
for (const scheme of ["light", "dark"] as const) {
35+
act(() => {
36+
colorScheme.set(scheme);
37+
});
38+
39+
expect(styleOf("a")).toStrictEqual({ color: "#f00" });
40+
expect(styleOf("b")).toBeUndefined();
41+
expect(styleOf("c")).toStrictEqual({ color: "#008000" });
42+
}
43+
});
44+
45+
test("a declaration that fails to parse drops alone", () => {
46+
registerCSS(`.a { color: var(); width: 10px } .c { color: green }`);
47+
48+
render(
49+
<>
50+
<View testID="a" className="a" />
51+
<View testID="c" className="c" />
52+
</>,
53+
);
54+
55+
expect(styleOf("a")).toStrictEqual({ width: 10 });
56+
expect(styleOf("c")).toStrictEqual({ color: "#008000" });
57+
});
58+
});

0 commit comments

Comments
 (0)