Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ElijahAhianyo committed Apr 23, 2024
1 parent 0857f8e commit d7bbc82
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions reflex/components/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ def __init__(self, *args, **kwargs):
Raises:
TypeError: If an invalid prop is passed.
ValueError: If an event trigger is passed is not valid.
"""
# Set the id and children initially.
children = kwargs.get("children", [])
Expand Down
25 changes: 25 additions & 0 deletions tests/components/test_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -1569,3 +1569,28 @@ class TestComponent(Component):
parse_args_spec(custom_triggers[trigger_name]),
):
assert v1.equals(v2)


def test_invalid_event_trigger():
class TriggerComponent(Component):
on_push: Var[bool]

def get_event_triggers(self) -> Dict[str, Any]:
"""Test controlled triggers.
Returns:
Test controlled triggers.
"""
return {
**super().get_event_triggers(),
"on_a": lambda: [],
}

trigger_comp = TriggerComponent.create

# test that these do not throw errors.
trigger_comp(on_push=True)
trigger_comp(on_a=rx.console_log("log"))

with pytest.raises(ValueError):
trigger_comp(on_b=rx.console_log("log"))

0 comments on commit d7bbc82

Please sign in to comment.