View source: R/use_shiny_testers.R
use_shiny_testers | R Documentation |
Enable 'update' functions in the Shiny or Shiny extension package to be mocked in tests.
use_shiny_testers(..., .package = "shiny", .env = rlang::caller_env())
with_shiny_testers(code, ..., .package = "shiny")
... |
Arguments passed to |
.package |
Character string of the package that the update functions exist in. Default is '"shiny"' |
.env |
Environment that defines effect scope. For expert use only. |
code |
Code to execute with specified bindings. |
Implicit return of the updated functions in the supplied package within the specified environment.
library(shiny)
library(testthat)
example_server_fn <- function(input, output, session) {
observeEvent(input$trigger, {
updateTextInput(
inputId = "result",
label = "New Label",
value = NULL,
placeholder = "New placeholder"
)
})
}
test_that("Check that text input gets updated", {
use_shiny_testers()
shiny::testServer(
app = example_server_fn,
expr = {
session$setInputs(result = "Example text")
session$setInputs(trigger = 1L)
expect_identical(input$result, "Example text")
expect_identical(input$result.label, "New Label")
expect_identical(input$result.placeholder, "New placeholder")
}
)
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.