Skip to content

Commit 0269b0f

Browse files
committed
add test for covering theme_sub items
1 parent 895dd2f commit 0269b0f

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tests/testthat/test-theme.R

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,28 @@ test_that("geom elements are inherited correctly", {
736736
expect_equal(p$colour, "red")
737737
})
738738

739+
test_that("theme elements are covered in `theme_sub_*()` functions", {
740+
# We use a snapshot test here to trigger when a new theme element is added
741+
# or removed.
742+
# A failure of this test should be taken as a prompt to see if the new
743+
# theme element should be included in one of the `theme_sub_*` functions.
744+
745+
fmls <- paste0("axis.", fn_fmls_names(theme_sub_axis))
746+
fmls <- c(fmls, paste0("axis.", fn_fmls_names(theme_sub_axis_x), ".x"))
747+
fmls <- c(fmls, paste0("axis.", fn_fmls_names(theme_sub_axis_y), ".y"))
748+
fmls <- c(fmls, paste0("axis.", fn_fmls_names(theme_sub_axis_top), ".x.top"))
749+
fmls <- c(fmls, paste0("axis.", fn_fmls_names(theme_sub_axis_bottom), ".x.bottom"))
750+
fmls <- c(fmls, paste0("axis.", fn_fmls_names(theme_sub_axis_left), ".y.left"))
751+
fmls <- c(fmls, paste0("axis.", fn_fmls_names(theme_sub_axis_right), ".y.right") )
752+
fmls <- c(fmls, paste0("legend.", fn_fmls_names(theme_sub_legend)))
753+
fmls <- c(fmls, paste0("plot.", fn_fmls_names(theme_sub_plot)))
754+
fmls <- c(fmls, paste0("panel.", fn_fmls_names(theme_sub_panel)))
755+
fmls <- c(fmls, paste0("strip.", fn_fmls_names(theme_sub_strip)))
756+
757+
extra_elements <- setdiff(fn_fmls_names(theme), fmls)
758+
expect_snapshot(extra_elements)
759+
})
760+
739761
# Visual tests ------------------------------------------------------------
740762

741763
test_that("element_polygon() can render a grob", {

0 commit comments

Comments
 (0)