Skip to content

Commit 2b8b7c1

Browse files
committed
Add extra test for validator called before dom ready, update changelog
1 parent 591b692 commit 2b8b7c1

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
## Unreleased
9+
10+
### Fixed
11+
12+
- Fixed validator not running on first reactive set https://github.com/Textualize/textual/pull/1359
813

914
## [0.6.0] - 2022-12-11
1015

tests/test_reactive.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,27 @@ def validate_count(self, value: int) -> int:
194194
assert validator_call_count == 1
195195

196196

197+
async def test_validate_init_true_set_before_dom_ready():
198+
"""When init is True for a reactive attribute, Textual should call the validator
199+
AND the watch method when the app starts."""
200+
validator_call_count = 0
201+
202+
class ValidatorInitTrue(App):
203+
count = var(5, init=True)
204+
205+
def validate_count(self, value: int) -> int:
206+
nonlocal validator_call_count
207+
validator_call_count += 1
208+
return value + 1
209+
210+
app = ValidatorInitTrue()
211+
app.count = 5
212+
async with app.run_test():
213+
assert app.count == 6 # Validator should run, so value should be 5+1=6
214+
assert validator_call_count == 1
215+
216+
217+
197218
@pytest.mark.xfail(reason="Compute methods not called when init=True [issue#1227]")
198219
async def test_reactive_compute_first_time_set():
199220
class ReactiveComputeFirstTimeSet(App):

0 commit comments

Comments
 (0)