Skip to content

Commit f64e871

Browse files
Update tests
1 parent ac3376e commit f64e871

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/reactpy/executors/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,16 @@ def vdom_head_to_html(head: VdomDict) -> str:
4848

4949

5050
def html_noscript_to_html(
51-
html_noscript: str | Path | Component | RootComponentConstructor | None,
51+
html_noscript: str | Path | VdomDict | Component | RootComponentConstructor | None,
5252
) -> str:
5353
if html_noscript is None:
5454
return ""
5555
if isinstance(html_noscript, Path):
5656
html_noscript = html_noscript.read_text()
57-
elif isinstance(html_noscript, Component):
58-
html_noscript = reactpy_to_string(html_noscript)
5957
elif callable(html_noscript):
6058
html_noscript = reactpy_to_string(html_noscript())
59+
elif isinstance(html_noscript, dict):
60+
html_noscript = reactpy_to_string(html_noscript)
6161
return f"<noscript>{html_noscript}</noscript>"
6262

6363

tests/test_asgi/test_utils.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import reactpy
66
from reactpy import config, html
77
from reactpy.executors import utils
8+
from reactpy.types import VdomDict
89

910

1011
def test_invalid_vdom_head():
@@ -30,7 +31,7 @@ def test_html_noscript_string_to_html():
3031
)
3132

3233

33-
def test_html_noscript_component_to_html():
34+
def test_html_noscript_as_uncalled_component():
3435
@reactpy.component
3536
def message():
3637
return html.p({"id": "noscript-message"}, "Please enable JavaScript.")
@@ -41,6 +42,23 @@ def message():
4142
)
4243

4344

45+
def test_html_noscript_as_function():
46+
def message():
47+
return html.p({"id": "noscript-message"}, "Please enable JavaScript.")
48+
49+
assert (
50+
utils.html_noscript_to_html(message())
51+
== '<noscript><p id="noscript-message">Please enable JavaScript.</p></noscript>'
52+
)
53+
54+
55+
def test_html_noscript_as_vdom_dict():
56+
assert (
57+
utils.html_noscript_to_html(VdomDict(tagName="div", children=[html.p({"id": "noscript-message"}, "Please enable JavaScript.")] ))
58+
== '<noscript><div><p id="noscript-message">Please enable JavaScript.</p></div></noscript>'
59+
)
60+
61+
4462
def test_html_noscript_none_to_html():
4563
assert utils.html_noscript_to_html(None) == ""
4664

0 commit comments

Comments
 (0)