From 648001cc189bab72dd62c1ac912584fb051c6b3f Mon Sep 17 00:00:00 2001 From: Teun van den Brand <49372158+teunbrand@users.noreply.github.com> Date: Fri, 19 Jan 2024 08:24:25 +0100 Subject: [PATCH] Test for absence/presence of guide differently (#89) * test for absence/presence of guide differently * narrate the conditional logic --- tests/testthat/test_scale_cyclical.R | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test_scale_cyclical.R b/tests/testthat/test_scale_cyclical.R index a25b459..ef9ea76 100644 --- a/tests/testthat/test_scale_cyclical.R +++ b/tests/testthat/test_scale_cyclical.R @@ -12,7 +12,12 @@ 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) + # in ggplot2 >= 3.5.0 legend structure in gtable changed + 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() + @@ -23,7 +28,12 @@ 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) + # in ggplot2 >= 3.5.0 legend structure in gtable changed + 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(