Skip to content

Commit

Permalink
Added test to check for error messages when using non-existent runnin…
Browse files Browse the repository at this point in the history
…g components and not suppressing callback exceptions
  • Loading branch information
aGitForEveryone authored Jun 24, 2024
1 parent 7c172b4 commit 014bec7
Showing 1 changed file with 58 additions and 1 deletion.
59 changes: 58 additions & 1 deletion tests/integration/callbacks/test_basic_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ def on_click(_):

def test_cbsc020_callback_running_non_existing_component(dash_duo):
lock = Lock()
app = Dash(__name__)
app = Dash(__name__, suppress_callback_exceptions=True)

app.layout = html.Div(
[
Expand Down Expand Up @@ -858,3 +858,60 @@ def on_click(_):
dash_duo.find_element("#start").click()

dash_duo.wait_for_text_to_equal("#output", "done")


def test_cbsc021_callback_running_non_existing_component(dash_duo):
lock = Lock()
app = Dash(__name__)

app.layout = html.Div(
[
html.Button("start", id="start"),
html.Div(id="output"),
]
)

@app.callback(
Output("output", "children"),
Input("start", "n_clicks"),
running=[
[
Output("non_existent_component", "children"),
html.B("on", id="content"),
"off",
]
],
prevent_initial_call=True,
)
def on_click(_):
with lock:
pass
return "done"

dash_duo.start_server(
app,
debug=True,
use_reloader=False,
use_debugger=True,
dev_tools_hot_reload=False,
)
with lock:
dash_duo.find_element("#start").click()

dash_duo.wait_for_text_to_equal("#output", "done")
error_title = "ID running component not found in layout"
error_message = [
"Component defined in running keyword not found in layout.",
'Component id: "non_existent_component"',
"This ID was used in the callback(s) for Output(s):",
"output.children",
"You can suppress this exception by setting",
"`suppress_callback_exceptions=True`.",
]
# The error should show twice, once for trying to set running on and once for
# turning it off.
dash_duo.wait_for_text_to_equal(dash_duo.devtools_error_count_locator, "2")
for error in dash_duo.find_elements(".dash-fe-error__title"):
assert error.text == error_title
for error_text in dash_duo.find_elements(".dash-backend-error"):
assert all(line in error_text for line in error_message)

0 comments on commit 014bec7

Please sign in to comment.