Skip to content

Commit 78a1608

Browse files
committed
ensure differences between layers, so test fails when appropriate
1 parent f46636a commit 78a1608

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

tests/testthat/test-layer.R

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,9 @@ test_that("layer_data returns a data.frame", {
227227
})
228228

229229
test_that("get_layer_data works with layer names", {
230-
p <- ggplot() + geom_point(name = "foo") + geom_point(name = "bar")
230+
p <- ggplot() +
231+
annotate("point", x = 1, y = 1, name = "foo") +
232+
annotate("line", x = 1:2, y = 1:2, name = "bar")
231233

232234
# name has higher precedence than index
233235
expect_identical(
@@ -237,13 +239,15 @@ test_that("get_layer_data works with layer names", {
237239
})
238240

239241
test_that("get_layer_grob works with layer names", {
240-
p <- ggplot() + geom_point(name = "foo") + geom_point(name = "bar")
242+
p <- ggplot() +
243+
annotate("point", x = 1, y = 1, name = "foo") +
244+
annotate("line", x = 1:2, y = 1:2, name = "bar")
241245

242246
# name has higher precedence than index
243-
expect_identical(
244-
get_layer_grob(p, i = "bar"),
245-
get_layer_grob(p, i = 2L)
246-
)
247+
named <- get_layer_grob(p, i = "bar")
248+
nummed <- get_layer_grob(p, i = 2L)
249+
named[[1]]$name <- nummed[[1]]$name <- NULL # ignore grid's unique names
250+
expect_identical(named, nummed)
247251
})
248252

249253
test_that("data.frames and matrix aesthetics survive the build stage", {

0 commit comments

Comments
 (0)