Skip to content

Commit

Permalink
test for absence/presence of guide differently
Browse files Browse the repository at this point in the history
  • Loading branch information
teunbrand committed Jan 17, 2024
1 parent 54c8670 commit e43884a
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions tests/testthat/test_scale_cyclical.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ test_that("basic tests", {
expect_equal(d$colour, rep(c("#F00000", "#0000F0"), 13))

# make sure there is no legend being generated
expect_equal("guide-box" %in% ggplotGrob(p)$layout$name, FALSE)
if ("get_guide_data" %in% getNamespaceExports("ggplot2")) {
expect_null(get_guide_data(p, "colour"))
} else {
expect_equal("guide-box" %in% ggplotGrob(p)$layout$name, FALSE)
}

# once again, different aesthetic, different cyclical pattern, now with legend
p <- ggplot(df, aes(x, y, label=letters, color=factor(x))) + geom_text() +
Expand All @@ -23,7 +27,11 @@ test_that("basic tests", {
expect_equal(d$colour[order(d$x)], rep(c("#F00000", "#0000F0", "#F0F000"), 9)[1:26])

# make sure there is a legend
expect_equal("guide-box" %in% ggplotGrob(p)$layout$name, TRUE)
if ("get_guide_data" %in% getNamespaceExports("ggplot2")) {
expect_s3_class(get_guide_data(p, "colour"), "data.frame")
} else {
expect_equal("guide-box" %in% ggplotGrob(p)$layout$name, TRUE)
}

# test that breaks must match labels
expect_error(
Expand Down

0 comments on commit e43884a

Please sign in to comment.