hi all,
Is there a way to trigger action button inside test server .
If you see below, the default value is 5 and when the user clicks on button, the value 10 displays.
I need to test above scenario where test server triggers the action automatically when we run the test and should check expect_equal(myreactive(), 10)
so it passes. Can we achieve this?
library(testthat)
library(shiny)
app <- shinyApp(
ui = fluidPage(
numericInput("x", "X", value = 5),
textOutput("txt"),
actionButton("press", "Submit")
),
server = function(input, output, session) {
myreactive <- reactive({
input$x * 2
})
observeEvent(input$press,{
output$txt <- renderText({
paste0("I am ", myreactive())
})
})
}
)
testServer(app, {
session$setInputs(press = 1)
expect_equal(myreactive(), 10)
})