Skip to content

Commit 77a047a

Browse files
test(native): cover an inherited cycle reached from two branches, and the compiler's cut (#422)
1 parent d42c649 commit 77a047a

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

‎src/__tests__/native/variable-cycles.test.tsx‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,36 @@ test("repeated sibling variable references are not cycles", () => {
6969
render(<View testID="sample" className="sample" />);
7070
expect(screen.getByTestId("sample").props.style).toStrictEqual({ width: 40 });
7171
});
72+
73+
const nested = (
74+
<View className="parent">
75+
<View className="mid">
76+
<View testID="child" className="child" />
77+
</View>
78+
</View>
79+
);
80+
81+
// A variable reaches a descendant unresolved, so this cycle closes on the element that reads it
82+
test("one variable reached again from two branches of one value, inherited, drops the reading declaration", () => {
83+
registerCSS(
84+
`.parent { --a: red; --b: blue; --c: green; --unrelated: 1; }
85+
.mid { --a: var(--b) var(--c); --b: var(--a); --c: var(--a); --unrelated: 0.5; }
86+
.child { color: var(--a); opacity: var(--unrelated); }`,
87+
{ inlineVariables: false },
88+
);
89+
render(nested);
90+
expect(screen.getByTestId("child").props.style).toStrictEqual({
91+
opacity: 0.5,
92+
});
93+
});
94+
95+
test("a cycle in a variable declared once is cut by the compiler", () => {
96+
registerCSS(
97+
`.mid { --unrelated: 0.5; }
98+
.child { --z: var(--z); width: var(--z); opacity: var(--unrelated); }`,
99+
);
100+
render(nested);
101+
expect(screen.getByTestId("child").props.style).toStrictEqual({
102+
opacity: 0.5,
103+
});
104+
});

0 commit comments

Comments
 (0)