File tree Expand file tree Collapse file tree 2 files changed +22
-4
lines changed
Expand file tree Collapse file tree 2 files changed +22
-4
lines changed Original file line number Diff line number Diff line change @@ -48,16 +48,16 @@ def vdom_head_to_html(head: VdomDict) -> str:
4848
4949
5050def 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
Original file line number Diff line number Diff line change 55import reactpy
66from reactpy import config , html
77from reactpy .executors import utils
8+ from reactpy .types import VdomDict
89
910
1011def 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+
4462def test_html_noscript_none_to_html ():
4563 assert utils .html_noscript_to_html (None ) == ""
4664
You can’t perform that action at this time.
0 commit comments