I want to test the server function of a shiny module via shiny::testServer(). This module, lets call it module "Two", is dependent on another shiny module called module "One".
My problem is that I don't know how to access the return value of module "One", when testing module "Two".
Example
Testing module "One", which is independent works like charm:
library("shiny")
library("testthat")
moduleOneServer <- function(id) {
moduleServer(id, function(input, output, session) {
myreactive <- reactive({input$name})
hiName <- renderText({paste("Hi", myreactive())})
hiName
})
}
test_that("Test moduleOneServer", {
testServer(moduleOneServer, {
session$setInputs(name = "Liza")
expect_equal(session$returned(), "Hi Liza")
session$setInputs(name = "Frank")
expect_equal(session$returned(), "Hi Frank")
})
})
When trying to test module "Two" I need to access the return value of module "One". The following does not work (maybe my moduleTwoServer syntax is also wrong...):
moduleTwoServer <- function(id, name) {
moduleServer(id, function(input, output, session) {
output$plot <- renderPlot({
req(name())
plot(x=1, y=1, main = name())
})
})
}
test_that("Test moduleTwoServer", {
testServer(moduleTwoServer,
args = list(name = moduleOneServer("name")), {
output$plot # Test existance of plot
})
})