mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Add extra test for validator called before dom ready, update changelog
This commit is contained in:
@@ -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/)
|
||||
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
|
||||
|
||||
|
||||
@@ -194,6 +194,27 @@ async def test_validate_init_true():
|
||||
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]")
|
||||
async def test_reactive_compute_first_time_set():
|
||||
class ReactiveComputeFirstTimeSet(App):
|
||||
|
||||
Reference in New Issue
Block a user