diff --git a/src/__tests__/native/variable-cycles.test.tsx b/src/__tests__/native/variable-cycles.test.tsx index 6854317f..e68ee529 100644 --- a/src/__tests__/native/variable-cycles.test.tsx +++ b/src/__tests__/native/variable-cycles.test.tsx @@ -69,3 +69,36 @@ test("repeated sibling variable references are not cycles", () => { render(); expect(screen.getByTestId("sample").props.style).toStrictEqual({ width: 40 }); }); + +const nested = ( + + + + + +); + +// A variable reaches a descendant unresolved, so this cycle closes on the element that reads it +test("one variable reached again from two branches of one value, inherited, drops the reading declaration", () => { + registerCSS( + `.parent { --a: red; --b: blue; --c: green; --unrelated: 1; } + .mid { --a: var(--b) var(--c); --b: var(--a); --c: var(--a); --unrelated: 0.5; } + .child { color: var(--a); opacity: var(--unrelated); }`, + { inlineVariables: false }, + ); + render(nested); + expect(screen.getByTestId("child").props.style).toStrictEqual({ + opacity: 0.5, + }); +}); + +test("a cycle in a variable declared once is cut by the compiler", () => { + registerCSS( + `.mid { --unrelated: 0.5; } + .child { --z: var(--z); width: var(--z); opacity: var(--unrelated); }`, + ); + render(nested); + expect(screen.getByTestId("child").props.style).toStrictEqual({ + opacity: 0.5, + }); +});