test_bare.py 764 B

1234567891011121314151617181920212223242526272829
  1. import pytest
  2. from reflex.components.base.bare import Bare
  3. from reflex.vars.base import Var
  4. STATE_VAR = Var(_js_expr="default_state.name")
  5. @pytest.mark.parametrize(
  6. "contents,expected",
  7. [
  8. ("hello", '{"hello"}'),
  9. ("{}", '{"{}"}'),
  10. (None, '{""}'),
  11. (STATE_VAR, "{default_state.name}"),
  12. # This behavior is now unsupported.
  13. # ("${default_state.name}", "${default_state.name}"),
  14. # ("{state.name}", "{state.name}"),
  15. ],
  16. )
  17. def test_fstrings(contents, expected):
  18. """Test that fstrings are rendered correctly.
  19. Args:
  20. contents: The contents of the component.
  21. expected: The expected output.
  22. """
  23. comp = Bare.create(contents).render()
  24. assert comp["contents"] == expected