mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
27 lines
631 B
Python
27 lines
631 B
Python
from textual.app import App, ComposeResult
|
|
from textual.reactive import reactive
|
|
|
|
|
|
class WatchApp(App):
|
|
|
|
count = reactive(0, init=False)
|
|
|
|
test_count = 0
|
|
|
|
def watch_count(self, value: int) -> None:
|
|
self.test_count = value
|
|
|
|
|
|
async def test_watch():
|
|
"""Test that changes to a watched reactive attribute happen immediately."""
|
|
app = WatchApp()
|
|
async with app.run_test():
|
|
app.count += 1
|
|
assert app.test_count == 1
|
|
app.count += 1
|
|
assert app.test_count == 2
|
|
app.count -= 1
|
|
assert app.test_count == 1
|
|
app.count -= 1
|
|
assert app.test_count == 0
|