Skip to content

Commit

Permalink
test reset schedule_render_later
Browse files Browse the repository at this point in the history
  • Loading branch information
rmorshea committed Feb 25, 2022
1 parent 5b8ab7d commit fdad4fd
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/test_core/test_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
from idom import html
from idom.core.dispatcher import render_json_patch
from idom.core.hooks import COMPONENT_DID_RENDER_EFFECT, LifeCycleHook, current_hook
from idom.core.layout import Layout
from idom.testing import HookCatcher, assert_idom_logged
from idom.utils import Ref
from tests.assert_utils import assert_same_items


Expand Down Expand Up @@ -1139,3 +1141,25 @@ def bad_effect():
await layout.render()
component_hook.latest.schedule_render()
await layout.render() # no error


async def test_set_state_during_render():
render_count = Ref(0)

@idom.component
def SetStateDuringRender():
render_count.current += 1
state, set_state = idom.use_state(0)
if not state:
set_state(state + 1)
return html.div(state)

with Layout(SetStateDuringRender()) as layout:
await layout.render()
assert render_count.current == 1
await layout.render()
assert render_count.current == 2

# there should be no more renders to perform
with pytest.raises(asyncio.exceptions.TimeoutError):
await asyncio.wait_for(layout.render(), timeout=0.1)

0 comments on commit fdad4fd

Please sign in to comment.