Repository: plotly/dash
File: components/dash-core-components/tests/integration/dropdown/test_remove_option.py (Python)

Code before:
                value=value,
                searchable=searchable,
                id="dropdown",
            ),
            html.Button("Remove option", id="remove"),
            html.Div(id="value-output"),
        ]
    )

    @app.callback(Output("dropdown", "options"), [Input("remove", "n_clicks")])
    def on_click(n_clicks):
        if not n_clicks:
            raise PreventUpdate
        return sample_dropdown_options[:-1]

    @app.callback(Output("value-output", "children"), [Input("dropdown", "value")])
    def on_change(val):
        if not val:
            raise PreventUpdate
        return val or "None"

    dash_dcc.start_server(app)
    btn = dash_dcc.wait_for_element("#remove")
    btn.click()

    dash_dcc.wait_for_text_to_equal("#value-output", "None")


@pytest.mark.parametrize("searchable", (True, False))
def test_ddro002_remove_option_multi(dash_dcc, searchable):
    dropdown_options = sample_dropdown_options

    app = Dash(__name__)
    value = ["MTL", "SF"]

    app.layout = html.Div(
        [
            dcc.Dropdown(
                options=dropdown_options,
                value=value,
                multi=True,
                id="dropdown",
                searchable=searchable,
            ),
            html.Button("Remove option", id="remove"),
            html.Div(id="value-output"),
        ]
    )

    @app.callback(Output("dropdown", "options"), [Input("remove", "n_clicks")])
    def on_click(n_clicks):

Review comment (suggestion):
@TillerBurr While investigating this issue earlier, I found a quirk of `wait_for_text_to_equal` which gives false positives when used with the text`"None"`.

I recommend to try changing this string to anything besides `"None"` (both here and on line 46) and see whether the test still passes.


Code after:
                value=value,
                searchable=searchable,
                id="dropdown",
            ),
            html.Button("Remove option", id="remove"),
            html.Div(id="value-output"),
        ]
    )

    @app.callback(Output("dropdown", "options"), [Input("remove", "n_clicks")])
    def on_click(n_clicks):
        if not n_clicks:
            raise PreventUpdate
        return sample_dropdown_options[:-1]

    @app.callback(Output("value-output", "children"), [Input("dropdown", "value")])
    def on_change(val):
        return val or "Nothing Here"

    dash_dcc.start_server(app)
    btn = dash_dcc.wait_for_element("#remove")
    btn.click()

    dash_dcc.wait_for_text_to_equal("#value-output", "Nothing Here")


@pytest.mark.parametrize("searchable", (True, False))
def test_ddro002_remove_option_multi(dash_dcc, searchable):
    dropdown_options = sample_dropdown_options

    app = Dash(__name__)
    value = ["MTL", "SF"]

    app.layout = html.Div(
        [
            dcc.Dropdown(
                options=dropdown_options,
                value=value,
                multi=True,
                id="dropdown",
                searchable=searchable,
            ),
            html.Button("Remove option", id="remove"),
            html.Div(id="value-output"),
        ]
    )

    @app.callback(Output("dropdown", "options"), [Input("remove", "n_clicks")])
    def on_click(n_clicks):
        if not n_clicks:
            raise PreventUpdate