Need help relating to tests for application #5965
Unanswered
jamesalphanome
asked this question in
Q&A
Replies: 1 comment
|
On Reflex 0.11.0, you can test a synchronous event handler directly in pytest. Create a fresh state instance, call the handler, and assert what changed. A second test can check that the component binds the expected handler to its click event. This example passed with Python 3.12.8 and Reflex 0.11.0. import reflex as rx
class Counter(rx.State):
count: int = 0
@rx.event
def increment(self):
self.count += 1
def increment_button():
return rx.button("Add one", on_click=Counter.increment)
def test_increment():
state = Counter()
state.increment()
assert state.count == 1
def test_button_calls_increment():
click = increment_button().event_triggers["on_click"]
assert [event.handler for event in click.events] == [Counter.increment]Save it as |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Can anyone give any suggestions on how to write unit tests for components and eventhandlers ?
All reactions