Skip to content

Commit 6ac8bf4

Browse files
Add unit tests for EventVar and EventChainVar bool() methods
Co-Authored-By: khaleel@reflex.dev <khaleel.aladhami@gmail.com>
1 parent 8934bfb commit 6ac8bf4

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tests/units/test_event.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,3 +483,32 @@ def get_handler(self, arg: Var[str]):
483483

484484
w = Wrapper()
485485
_ = rx.input(on_change=w.get_handler)
486+
487+
488+
def test_event_var_bool_conversion():
489+
"""Test that EventVar and EventChainVar cannot be converted to booleans."""
490+
491+
class S(BaseState):
492+
@event
493+
def s(self):
494+
pass
495+
496+
handler_var = Var.create(S.s)
497+
with pytest.raises(TypeError) as err:
498+
handler_var.bool()
499+
assert "Cannot convert" in str(err.value)
500+
assert "to bool" in str(err.value)
501+
502+
def _args_spec() -> tuple:
503+
return ()
504+
505+
chain_var = Var.create(
506+
EventChain(
507+
events=[S.s()],
508+
args_spec=_args_spec,
509+
)
510+
)
511+
with pytest.raises(TypeError) as err:
512+
chain_var.bool()
513+
assert "Cannot convert" in str(err.value)
514+
assert "to bool" in str(err.value)

0 commit comments

Comments
 (0)