Update 'Shiny' Inputs when using testServer()

Create mocked bindings to 'Shiny' update functions within test function calls to automatically update input values. The mocked bindings simulate the communication between the server and UI components of a 'Shiny' module in testServer().


R-CMD-check Codecov test coverage

shinytesters

The aim of shinytesters is to make it easier to test update functions in Shiny packages when using testthat::testServer.

Installation

To install the latest development version of shinytesters, install from GitHub:

remotes::install_github("ashbaldry/shinytesters")

Usage

Add use_shiny_testers() at the start of any test that is using shiny::testServer to add inputs and other relevant arguments to the test session inputs.

test_that("When clicking apply button, checkbox becomes checked", {
  use_shiny_testers()

  example_server_fn <- function(input, output, session) {
    observeEvent(input$apply_btn, {
      updateCheckboxInput(
        inputId = "result",
        label = "New Label",
        value = TRUE
      )
    })
  }

  shiny::testServer(
    app = example_server_fn,
    expr = {
      session$setInputs(apply_btn = 1L)

      expect_identical(input$result, TRUE)
      expect_identical(input$result.label, "New Label")
    }
  )
})

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("shinytesters")

0.1.0 by Ashley Baldry, a year ago


https://ashbaldry.github.io/shinytesters/


Report a bug at https://github.com/ashbaldry/shinytesters/issues


Browse source code at https://github.com/cran/shinytesters


Authors: Ashley Baldry [aut, cre]


Documentation:   PDF Manual  


GPL-3 license


Imports cli, rlang

Suggests knitr, rmarkdown, shiny, testthat


See at CRAN