File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
55The format is based on [ Keep a Changelog] ( http://keepachangelog.com/ )
66and 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
Original file line number Diff line number Diff 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]" )
198219async def test_reactive_compute_first_time_set ():
199220 class ReactiveComputeFirstTimeSet (App ):
You can’t perform that action at this time.
0 commit comments