test_form.py 737 B

123456789101112131415161718192021
  1. from reflex.components.radix.primitives.form import Form
  2. from reflex.event import EventChain
  3. from reflex.ivars.base import ImmutableVar
  4. def test_render_on_submit():
  5. """Test that on_submit event chain is rendered as a separate function."""
  6. submit_it = ImmutableVar(
  7. _var_name="submit_it",
  8. _var_type=EventChain,
  9. )
  10. f = Form.create(on_submit=submit_it)
  11. exp_submit_name = f"handleSubmit_{f.handle_submit_unique_name}" # type: ignore
  12. assert f"onSubmit={{{exp_submit_name}}}" in f.render()["props"]
  13. def test_render_no_on_submit():
  14. """A form without on_submit should not render a submit handler."""
  15. f = Form.create()
  16. for prop in f.render()["props"]:
  17. assert "onSubmit" not in prop