I write some shiny tests recently using testServer which is great in most of the scenarios. I'm thinking about following problem which I can't solve now.
Let's imagine simple modules (ui/server)
child_ui <- function(id) {
ns <- NS(id)
div(
selectInput(inputId = ns("select"), label = "select", choices = c("a", "b"), selected = "a"),
verbatimTextOutput(outputId = ns("out"))
)
}
child_srv <- function(id) {
moduleServer(id, function(input, output, session) {
output$out <- renderPrint(input$select)
})
}
... which are called inside of the other module but through the specific function call_child.
parent_ui <- function(id, module) {
ns <- NS(id)
div(
module(ns("parent"))
)
}
parent_srv <- function(id, module) {
moduleServer(id, function(input, output, session) {
call_child <- function(module) {
module(id = "parent")
NULL
}
call_child(module)
})
}
What I would like to do is to check whether child_srv has been called and I wonder if there is some way to deduct this. Preferred solution is to keep call_child untouched (maybe some evidences are in session object).
The only thing I can do is following:
testServer(
app = parent_srv,
args = list(module = child_srv),
expr = {
tinytest::expect_null(call_child(module = module))
})
# example app
shinyApp(
ui = parent_ui(id = "root", module = child_ui),
server = function(input, output, session)
parent_srv(id = "root", module = child_srv)
)
Does anyone has any advice how to properly test this scenario?