Hi,
I have created an app that displays a datatable when a button is clicked.
I want to test the callback of this app using dash testing.
What is the correct set for expect?
app.py
from dash import Dash, html, callback, Output, Input, dash_table
import pandas as pd
table_df = pd.DataFrame(
columns = [f"columns_{i}" for i in range(2)],
index = [i for i in range(2)]
)
app = Dash(__name__)
app.layout = html.Div([
html.Button(
'Run',
id='run-button',
n_clicks=0
),
html.Div(
id="container",
)
])
@callback(
Output('container', 'children'),
Input('run-button', 'n_clicks'),
prevent_initial_call=True,
)
def show_datatable(n):
return dash_table.DataTable(table_df.to_dict('records'), [{"name": i, "id": i} for i in table_df.columns])
if __name__ == '__main__':
app.run_server(debug=True)
test_app.py
import pytest
from app import show_datatable
expect1 = "I am not sure what to put here."
@pytest.mark.parametrize('arg, expect', [
(1, expect1),
])
def test_show_datatable(arg, expect):
output = show_datatable(arg)
assert output == expect