Skip to content

Commit

Permalink
assert that .render returns jsonable values
Browse files Browse the repository at this point in the history
  • Loading branch information
adhami3310 committed Jan 29, 2025
1 parent 3bd2bea commit 04edc6d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 15 additions & 0 deletions reflex/components/tags/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,22 @@ def __iter__(self):
Yields:
Tuple[str, Any]: The field name and value.
"""
from reflex.components.component import BaseComponent

for field in dataclasses.fields(self):
value = getattr(self, field.name)
if isinstance(value, list):
children = []
for child in value:
if isinstance(child, BaseComponent):
children.append(child.render())
else:
children.append(child)
yield field.name, children
continue
if isinstance(value, BaseComponent):
yield field.name, value.render()
continue
yield field.name, getattr(self, field.name)

def add_props(self, **kwargs: Optional[Any]) -> Tag:
Expand Down
4 changes: 2 additions & 2 deletions tests/units/components/core/test_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def test_match_components():
assert fifth_return_value_render["name"] == "RadixThemesText"
assert fifth_return_value_render["children"][0]["contents"] == '{"sixth value"}'

default = match_child["default"].render()
default = match_child["default"]

assert default["name"] == "RadixThemesText"
assert default["children"][0]["contents"] == '{"default value"}'
Expand Down Expand Up @@ -153,7 +153,7 @@ def test_match_on_component_without_default():
match_comp = Match.create(MatchState.value, *match_case_tuples)
default = match_comp.render()["children"][0]["default"]

assert isinstance(default, Fragment)
assert isinstance(default, dict) and default["name"] == Fragment.__name__


def test_match_on_var_no_default():
Expand Down

0 comments on commit 04edc6d

Please sign in to comment.