Skip to content

Commit

Permalink
add pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
falkoschindler committed Dec 12, 2024
1 parent 98e42ad commit 318ba2a
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion tests/test_timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pytest

from nicegui import ui
from nicegui import app, ui
from nicegui.testing import Screen, User


Expand Down Expand Up @@ -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'

0 comments on commit 318ba2a

Please sign in to comment.