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

Function test_script_mount_unmount

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

Source from the content-addressed store, hash-verified

7
8
9async def test_script_mount_unmount(display: DisplayFixture):
10 toggle_is_mounted = Ref()
11
12 @component
13 def Root():
14 is_mounted, toggle_is_mounted.current = use_toggle(True)
15 return html.div(
16 html.div({"id": "mount-state", "data_value": False}),
17 HasScript() if is_mounted else html.div(),
18 )
19
20 @component
21 def HasScript():
22 return html.script(
23 """() => {
24 const mapping = {"false": false, "true": true};
25 const mountStateEl = document.getElementById("mount-state");
26 mountStateEl.setAttribute(
27 "data-value", !mapping[mountStateEl.getAttribute("data-value")]);
28 return () => mountStateEl.setAttribute(
29 "data-value", !mapping[mountStateEl.getAttribute("data-value")]);
30 }"""
31 )
32
33 await display.show(Root)
34
35 mount_state = await display.page.wait_for_selector("#mount-state", state="attached")
36 poll_mount_state = poll(mount_state.get_attribute, "data-value")
37
38 await poll_mount_state.until_equals("true")
39
40 toggle_is_mounted.current()
41
42 await poll_mount_state.until_equals("false")
43
44 toggle_is_mounted.current()
45
46 await poll_mount_state.until_equals("true")
47
48
49async def test_script_re_run_on_content_change(display: DisplayFixture):

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected