[Tests] add unit test for event (#614)

This commit is contained in:
Xiaojing Chen 2023-02-28 11:13:49 +08:00 committed by GitHub
parent 8f9b066794
commit b4c3cb5eb3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,3 +1,7 @@
import json
import pytest
from pynecone import event
from pynecone.event import Event, EventHandler, EventSpec
from pynecone.var import Var
@ -48,6 +52,21 @@ def test_call_event_handler():
assert event_spec.local_args == ()
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():
"""Test the event redirect function."""