Testing visuals

  • The second argument to expect_snapshot_file() gives the file name that the image will be saved in file snapshot directory.
  • If these tests are in a file called test-app.R, the snapshots will be saved:
    • tests/testthat/_snaps/app/plot-init.png
    • tests/testthat/_snaps/app/plot-update.png
  • To visualise the differences in a Shiny App run testthat::snapshot_review()
# Loading the app
app <- AppDriver$new(shinyApp(ui, server))

# Defining path to save screeenshot
path <- tempfile(fileext = ".png")

# Save screenshot to temporary file
app$get_screenshot(path)
expect_snapshot_file(path, "plot-init.png")

# Changing the input
app$set_inputs(x = 2)
app$get_screenshot(path)
expect_snapshot_file(path, "plot-update.png")