tests/testthat/test_gridifyClass.R

# Create a mock gridify object for testing
example_plot <- ggplot2::ggplotGrob(
  x = ggplot2::ggplot(data = mtcars, ggplot2::aes(x = mpg, y = wt)) +
    ggplot2::geom_line()
)

test_that("gridifyClass can be created with a proper input", {
  expect_silent(new("gridifyClass",
    object = example_plot,
    layout = simple_layout(),
    elements = list()
  ))
})


test_that(
  paste0(
    "gridifyClass has three cells of proper types:",
    "object, layout and elements"
  ),
  {
    class_spec <- getSlots("gridifyClass")

    expect_identical(class_spec, c(object = "ANY", layout = "gridifyLayout", elements = "list"))
  }
)


# We validate it on the gridify() function level
test_that("gridifyClass can be created with any type of object for output", {
  expect_silent(new("gridifyClass",
    object = 2,
    layout = simple_layout(),
    elements = list()
  ))

  expect_silent(new("gridifyClass",
    object = "any string",
    layout = simple_layout(),
    elements = list()
  ))
})

Try the gridify package in your browser

Any scripts or data that you put into this service are public.

gridify documentation built on Feb. 5, 2026, 5:09 p.m.