MCPcopy Index your code
hub / github.com/reactive-python/reactpy / test_script_from_src

Function test_script_from_src

src/py/reactpy/tests/test_html.py:92–130  ·  view source on GitHub ↗
(display: DisplayFixture)

Source from the content-addressed store, hash-verified

90
91
92async def test_script_from_src(display: DisplayFixture):
93 incr_src_id = Ref()
94 file_name_template = "__some_js_script_{src_id}__.js"
95
96 @component
97 def HasScript():
98 src_id, incr_src_id.current = use_counter(0)
99 if src_id == 0:
100 # on initial display we haven't added the file yet.
101 return html.div()
102 else:
103 return html.div(
104 html.div({"id": "run-count", "data_value": 0}),
105 html.script(
106 {
107 "src": f"/_reactpy/modules/{file_name_template.format(src_id=src_id)}"
108 }
109 ),
110 )
111
112 await display.show(HasScript)
113
114 for i in range(1, 4):
115 script_file = (
116 config.REACTPY_WEB_MODULES_DIR.current / file_name_template.format(src_id=i)
117 )
118 script_file.write_text(
119 f"""
120 let runCountEl = document.getElementById("run-count");
121 runCountEl.setAttribute("data-value", {i});
122 """
123 )
124
125 await poll(lambda: hasattr(incr_src_id, "current")).until_is(True)
126 incr_src_id.current()
127
128 run_count = await display.page.wait_for_selector("#run-count", state="attached")
129 poll_run_count = poll(run_count.get_attribute, "data-value")
130 await poll_run_count.until_equals("1")
131
132
133def test_script_may_only_have_one_child():

Callers

nothing calls this directly

Calls 6

RefClass · 0.90
pollClass · 0.90
showMethod · 0.80
until_isMethod · 0.80
until_equalsMethod · 0.80
currentMethod · 0.45

Tested by

no test coverage detected