test_script.py 992 B

12345678910111213141516171819202122232425262728293031
  1. """Test that element script renders correctly."""
  2. import pytest
  3. from reflex.components.base.script import Script
  4. def test_script_inline():
  5. """Test inline scripts are rendered as children."""
  6. component = Script.create("let x = 42")
  7. render_dict = component.render()["children"][0]
  8. assert render_dict["name"] == '"script"'
  9. assert not render_dict["contents"]
  10. assert len(render_dict["children"]) == 1
  11. assert render_dict["children"][0]["contents"] == '"let x = 42"'
  12. def test_script_src():
  13. """Test src prop is rendered without children."""
  14. component = Script.create(src="foo.js")
  15. render_dict = component.render()["children"][0]
  16. assert render_dict["name"] == '"script"'
  17. assert not render_dict["contents"]
  18. assert not render_dict["children"]
  19. assert 'src:"foo.js"' in render_dict["props"]
  20. def test_script_neither():
  21. """Specifying neither children nor src is a ValueError."""
  22. with pytest.raises(ValueError):
  23. Script.create()