MCPcopy
hub / github.com/reflex-dev/reflex / test_add_style_foreach

Function test_add_style_foreach

tests/units/components/test_component.py:2072–2090  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2070
2071
2072def test_add_style_foreach():
2073 class StyledComponent(Component):
2074 tag = "StyledComponent"
2075 ix: Var[int]
2076
2077 def add_style(self):
2078 return Style({"color": "red"})
2079
2080 page = rx.vstack(rx.foreach(Var.range(3), lambda i: StyledComponent.create(i)))
2081 page._add_style_recursive(Style())
2082
2083 # Expect only a single child of the foreach on the python side
2084 assert len(page.children[0].children) == 1
2085
2086 # Expect the style to be added to the child of the foreach
2087 assert 'css:({ ["color"] : "red" })' in str(page.children[0].children[0])
2088
2089 # Expect only one instance of this CSS dict in the rendered page
2090 assert str(page).count('css:({ ["color"] : "red" })') == 1
2091
2092
2093class TriggerState(rx.State):

Callers

nothing calls this directly

Calls 5

StyleClass · 0.90
foreachMethod · 0.80
rangeMethod · 0.45
createMethod · 0.45
_add_style_recursiveMethod · 0.45

Tested by

no test coverage detected