Skip to content

Commit

Permalink
make get_legend() test conditional
Browse files Browse the repository at this point in the history
  • Loading branch information
teunbrand committed Jan 18, 2024
1 parent 8cc3f1b commit 04be8d1
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion tests/testthat/test_get_legend.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ test_that("get legend", {
expect_equal(l$name, "guide-box")

# return null legend if no legend
expect_s3_class(get_legend(p + theme(legend.position = "none")), "zeroGrob")
# Note by Teun: It is yet unclear to me what the desired behaviour of
# `get_legend()` is in the face of multiple legends.
# For now, this test is conditional on ggplot2 version, but this is
# more of a duct tape solution than a reflection of the intended behaviour
if (utils::packageVersion("ggplot2") >= "3.5.0") {
expect_s3_class(get_legend(p + theme(legend.position = "none")), "zeroGrob")
} else {
expect_null(get_legend(p + theme(legend.position = "none")))
}
})

0 comments on commit 04be8d1

Please sign in to comment.