1
0

test_outbox.py 711 B

12345678910111213141516171819202122232425
  1. import asyncio
  2. from nicegui import ui
  3. from nicegui.testing import Screen
  4. def test_removing_outbox_loops(screen: Screen):
  5. @ui.page('/page', reconnect_timeout=0.1)
  6. def page():
  7. ui.button('Click me', on_click=lambda: ui.notify('Hello world!'))
  8. def count_outbox_loop_tasks() -> int:
  9. return len([t for t in asyncio.all_tasks() if t.get_name().startswith('outbox loop')])
  10. count = ui.label()
  11. ui.timer(0.1, lambda: count.set_text(f'{count_outbox_loop_tasks()} tasks'))
  12. screen.open('/page')
  13. screen.click('Click me')
  14. screen.should_contain('Hello world!')
  15. assert count.text == '1 tasks'
  16. screen.open('/')
  17. screen.wait(0.5)
  18. assert count.text == '0 tasks'