Skip to content

Commit 35db0c4

Browse files
committed
Add tests for clientside module imports
1 parent 0c62631 commit 35db0c4

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import {display} from "./clientsideModule.mjs";
2+
3+
window.dash_clientside.clientside_module = Object.assign({}, window.dash_clientside, {
4+
display
5+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const display = (value) => 'Client says "' + value + '"';
2+
3+
export {display};

tests/integration/clientside/test_clientside.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,3 +868,36 @@ def test_clsd020_clientside_callback_context_triggered_id(dash_duo):
868868
dash_duo.find_element("button[id*='btn1\":2']").click()
869869

870870
dash_duo.wait_for_text_to_equal("#output-clientside", "2")
871+
872+
873+
def test_clsd021_simple_clientside_module_serverside_callback(dash_duo):
874+
app = Dash(__name__, assets_folder="assets")
875+
876+
app.layout = html.Div(
877+
[
878+
dcc.Input(id="input"),
879+
html.Div(id="output-clientside"),
880+
html.Div(id="output-serverside"),
881+
]
882+
)
883+
884+
@app.callback(Output("output-serverside", "children"), [Input("input", "value")])
885+
def update_output(value):
886+
return 'Server says "{}"'.format(value)
887+
888+
app.clientside_callback(
889+
ClientsideFunction(namespace="clientside_module", function_name="display"),
890+
Output("output-clientside", "children"),
891+
[Input("input", "value")],
892+
)
893+
894+
dash_duo.start_server(app)
895+
896+
assert dash_duo.find_element("body > footer > script[type=module]")
897+
898+
dash_duo.wait_for_text_to_equal("#output-serverside", 'Server says "None"')
899+
dash_duo.wait_for_text_to_equal("#output-clientside", 'Client says "undefined"')
900+
901+
dash_duo.find_element("#input").send_keys("hello world")
902+
dash_duo.wait_for_text_to_equal("#output-serverside", 'Server says "hello world"')
903+
dash_duo.wait_for_text_to_equal("#output-clientside", 'Client says "hello world"')

0 commit comments

Comments
 (0)