[Tests] add unit test for event (#614)
This commit is contained in:
parent
8f9b066794
commit
b4c3cb5eb3
@ -1,3 +1,7 @@
|
|||||||
|
import json
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
from pynecone import event
|
from pynecone import event
|
||||||
from pynecone.event import Event, EventHandler, EventSpec
|
from pynecone.event import Event, EventHandler, EventSpec
|
||||||
from pynecone.var import Var
|
from pynecone.var import Var
|
||||||
@ -48,6 +52,21 @@ def test_call_event_handler():
|
|||||||
assert event_spec.local_args == ()
|
assert event_spec.local_args == ()
|
||||||
assert event_spec.args == (("arg1", "first"), ("arg2", "second"))
|
assert event_spec.args == (("arg1", "first"), ("arg2", "second"))
|
||||||
|
|
||||||
|
first, second = 123, "456"
|
||||||
|
handler = EventHandler(fn=test_fn_with_args)
|
||||||
|
event_spec = handler(first, second) # type: ignore
|
||||||
|
|
||||||
|
assert event_spec.handler == handler
|
||||||
|
assert event_spec.local_args == ()
|
||||||
|
assert event_spec.args == (
|
||||||
|
("arg1", json.dumps(first, ensure_ascii=False)),
|
||||||
|
("arg2", json.dumps(second, ensure_ascii=False)),
|
||||||
|
)
|
||||||
|
|
||||||
|
handler = EventHandler(fn=test_fn_with_args)
|
||||||
|
with pytest.raises(TypeError):
|
||||||
|
handler(test_fn) # type: ignore
|
||||||
|
|
||||||
|
|
||||||
def test_event_redirect():
|
def test_event_redirect():
|
||||||
"""Test the event redirect function."""
|
"""Test the event redirect function."""
|
||||||
|
Loading…
Reference in New Issue
Block a user