diff --git a/tests/test_timer.py b/tests/test_timer.py index efcad6d92..fe8925d85 100644 --- a/tests/test_timer.py +++ b/tests/test_timer.py @@ -3,7 +3,7 @@ import pytest -from nicegui import ui +from nicegui import app, ui from nicegui.testing import Screen, User @@ -145,3 +145,23 @@ def count(): await asyncio.sleep(0.1) gc.collect() assert count() == 1, 'only current timer object is in memory' + + +def test_app_timer(screen: Screen): + counter = Counter() + timer = app.timer(0.1, counter.increment) + ui.button('Activate', on_click=timer.activate) + ui.button('Deactivate', on_click=timer.deactivate) + + screen.open('/') + screen.wait(0.5) + assert counter.value > 0, 'timer is running after starting the server' + + screen.click('Deactivate') + value = counter.value + screen.wait(0.5) + assert counter.value == value, 'timer is not running anymore after deactivating it' + + screen.click('Activate') + screen.wait(0.5) + assert counter.value > value, 'timer is running again after activating it'