Skip to content
Discussion options

You must be logged in to vote

Like a few things within Textual, the value of the Select will only settle on a correct value once a DOM is available and the widget is fully mounted. It would be normal to test the working of the various widgets using App.run_test. For example:

from textual.app import App, ComposeResult
from textual.widgets import Select

class SelectApp(App[None]):

    INITIAL_VALUE = 3

    def compose(self) -> ComposeResult:
        yield Select[int]([(str(n), n) for n in range(10)], value=self.INITIAL_VALUE)

async def test_select_initial_value():
    async with SelectApp().run_test() as pilot:
        assert pilot.app.query_one(Select).value == SelectApp.INITIAL_VALUE

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by mzebrak
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #3034 on July 31, 2023 13:51.