Add extra test for validator called before dom ready, update changelog

This commit is contained in:
Darren Burns
2022-12-14 12:09:00 +00:00
parent 591b692720
commit 2b8b7c15e6
2 changed files with 26 additions and 0 deletions

View File

@@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/) The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/). and this project adheres to [Semantic Versioning](http://semver.org/).
## Unreleased
### Fixed
- Fixed validator not running on first reactive set https://github.com/Textualize/textual/pull/1359
## [0.6.0] - 2022-12-11 ## [0.6.0] - 2022-12-11

View File

@@ -194,6 +194,27 @@ async def test_validate_init_true():
assert validator_call_count == 1 assert validator_call_count == 1
async def test_validate_init_true_set_before_dom_ready():
"""When init is True for a reactive attribute, Textual should call the validator
AND the watch method when the app starts."""
validator_call_count = 0
class ValidatorInitTrue(App):
count = var(5, init=True)
def validate_count(self, value: int) -> int:
nonlocal validator_call_count
validator_call_count += 1
return value + 1
app = ValidatorInitTrue()
app.count = 5
async with app.run_test():
assert app.count == 6 # Validator should run, so value should be 5+1=6
assert validator_call_count == 1
@pytest.mark.xfail(reason="Compute methods not called when init=True [issue#1227]") @pytest.mark.xfail(reason="Compute methods not called when init=True [issue#1227]")
async def test_reactive_compute_first_time_set(): async def test_reactive_compute_first_time_set():
class ReactiveComputeFirstTimeSet(App): class ReactiveComputeFirstTimeSet(App):