server <- function(input, output, session){
# Move any complex logic into a separate reactive
# which can be tested comprehensively
plotData <- reactive({
data.frame(length = iris$Petal.Length, width = iris$Petal.Width)
})
# And leave the `render` function to be as simple as possible
# to lessen the need for integration tests.
output$plot <- renderPlot({
plot(plotData())
})
}
testServer(server, {
# Confirm that the data reactive is behaving as expected
expect_equal(nrow(plotData()), 150)
expect_equal(ncol(plotData()), 2)
expect_equal(colnames(plotData()), c("length", "width"))
# Just confirming that the plot can be accessed without an error
output$plot
})