Skip to content

Commit a79e7b2

Browse files
ned2chriddyp
authored andcommittedJan 19, 2018
added integration test
1 parent f28e19c commit a79e7b2

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
 

Diff for: ‎tests/test_integration.py

+48
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import dash_core_components as dcc
44
from dash import Dash
55
from dash.dependencies import Input, Output
6+
from dash.exceptions import PreventUpdate
67
from .IntegrationTests import IntegrationTests
78
from .utils import assert_clean_console, invincible, wait_for
89

@@ -64,3 +65,50 @@ def update_output(value):
6465
)
6566

6667
assert_clean_console(self)
68+
69+
def test_aborted_callback(self):
70+
"""Raising PreventUpdate prevents update and triggering dependencies"""
71+
72+
initial_input = 'initial input'
73+
initial_output = 'initial output'
74+
75+
app = Dash(__name__)
76+
app.layout = html.Div([
77+
dcc.Input(id='input', value=initial_input),
78+
html.Div(initial_output, id='output1'),
79+
html.Div(initial_output, id='output2'),
80+
])
81+
82+
callback1_count = Value('i', 0)
83+
callback2_count = Value('i', 0)
84+
85+
@app.callback(Output('output1', 'children'), [Input('input', 'value')])
86+
def callback1(value):
87+
callback1_count.value = callback1_count.value + 1
88+
raise PreventUpdate("testing callback does not update")
89+
return value
90+
91+
@app.callback(Output('output2', 'children'), [Input('output1', 'children')])
92+
def callback2(value):
93+
callback2_count.value = callback2_count.value + 1
94+
return value
95+
96+
self.startServer(app)
97+
98+
input_ = self.wait_for_element_by_id('input')
99+
input_.clear()
100+
input_.send_keys('x')
101+
output1 = self.wait_for_element_by_id('output1')
102+
output2 = self.wait_for_element_by_id('output2')
103+
104+
# callback1 runs twice (initial page load and through send_keys)
105+
self.assertEqual(callback1_count.value, 2)
106+
107+
# callback2 is never triggered, even on initial load
108+
self.assertEqual(callback2_count.value, 0)
109+
110+
# double check that output1 and output2 children were not updated
111+
self.assertEqual(output1.text, initial_output)
112+
self.assertEqual(output2.text, initial_output)
113+
114+
assert_clean_console(self)

0 commit comments

Comments
 (0)
Please sign in to comment.