rstudio / shinytest

Automated testing for shiny apps
https://rstudio.github.io/shinytest/
Other
225 stars 55 forks source link

Bug shinytest with rhandsontable when using `hot_validate_numeric` #413

Open stla opened 3 years ago

stla commented 3 years ago

Hello,

The app:

library(shiny)
library(rhandsontable)

ui <- fluidPage(
  br(),
  uiOutput("tables")
)

server <- function(input, output, session){

  output[["hot1"]] <- renderRHandsontable({
    rhandsontable(head(iris))
  })

  output[["hot2"]] <- renderRHandsontable({
    rhandsontable(head(iris)) 
  })

  output[["tables"]] <- renderUI({
    tagList(
      rHandsontableOutput("hot1"),
      br(),
      rHandsontableOutput("hot2")
    )
  })

}

shinyApp(ui, server)

The shinytest script:

library(shinytest)
app <- ShinyDriver$new(".", loadTimeout = 1e+05,
                       shinyOptions = list(test.mode = TRUE))
app$snapshotInit("mytest")

script <-
  "var table = HTMLWidgets.getInstance(hot1).hot;"
script2 <-
  "var t = document.getElementById('hot2').htmlwidget_data_init_result.hot;"

hot <-
  app$waitForValue("hot2", ignore = list(NULL), timeout=20000, iotype = "output")

app$snapshot()
app$executeScript(script)
app$executeScript(script2)
app$snapshot()

app$stop()

No problem.

Now, replace output[["hot2"]] with

  output[["hot2"]] <- renderRHandsontable({
    rhandsontable(head(iris)) %>%
      hot_validate_numeric(col = 1, min = 0, max = 100)
  })

The app works fine. But the shinytest script throws these errors:

> app$executeScript(script)
Error in session_makeRequest(self, private, endpoint, data, params, headers) : 
  undefined is not an object (evaluating 'HTMLWidgets.getInstance(hot1).hot')
> app$executeScript(script2)
Error in session_makeRequest(self, private, endpoint, data, params, headers) : 
  undefined is not an object (evaluating 'document.getElementById('hot2').htmlwidget_data_init_result.hot')
stla commented 3 years ago

Duplicate of https://github.com/rstudio/shinytest/issues/380